Skip to content

Commit

Permalink
sch-1926 (#86)
Browse files Browse the repository at this point in the history
* init

* more form work

* kinda finalize payment method styles

* lil better

* midas touch

* api ups

* space master

* add functions logic
  • Loading branch information
tenub authored Oct 7, 2024
1 parent 6dd9c4d commit 591fe20
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 355 deletions.
489 changes: 260 additions & 229 deletions components/src/components/elements/payment-method/PaymentMethod.tsx

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions components/src/components/elements/plan-manager/CheckoutDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ export const CheckoutDialog = () => {
clientSecret: setupIntent.setupIntentClientSecret,
}}
>
<Box $width="100%" $marginBottom="1.5rem">
<Text $size={18}>Add payment method</Text>
</Box>

<PaymentForm
plan={selectedPlan}
period={planPeriod}
Expand All @@ -652,12 +656,9 @@ export const CheckoutDialog = () => {
/>

{data.subscription?.paymentMethod && (
<Box
tabIndex={0}
onClick={() => setShowPaymentForm(false)}
$cursor="pointer"
>
<Box>
<Text
onClick={() => setShowPaymentForm(false)}
$font={theme.typography.link.fontFamily}
$size={theme.typography.link.fontSize}
$weight={theme.typography.link.fontWeight}
Expand All @@ -672,12 +673,9 @@ export const CheckoutDialog = () => {
<>
<PaymentMethod />

<Box
tabIndex={0}
onClick={() => setShowPaymentForm(true)}
$cursor="pointer"
>
<Box>
<Text
onClick={() => setShowPaymentForm(true)}
$font={theme.typography.link.fontFamily}
$size={theme.typography.link.fontSize}
$weight={theme.typography.link.fontWeight}
Expand Down
39 changes: 6 additions & 33 deletions components/src/components/elements/plan-manager/PaymentForm.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { useState } from "react";
import {
LinkAuthenticationElement,
PaymentElement,
} from "@stripe/react-stripe-js";
import { PaymentElement } from "@stripe/react-stripe-js";
import { useStripe, useElements } from "@stripe/react-stripe-js";
import type { CompanyPlanDetailResponseData } from "../../../api";
import { useEmbed } from "../../../hooks";
import { Box, Flex, Text } from "../../ui";
import { Box, Text } from "../../ui";
import { StyledButton } from "./styles";

interface PaymentFormProps {
plan: CompanyPlanDetailResponseData;
period: string;
plan?: CompanyPlanDetailResponseData;
period?: string;
onConfirm?: (paymentMethodId: string) => void;
}

export const PaymentForm = ({ plan, period, onConfirm }: PaymentFormProps) => {
export const PaymentForm = ({ onConfirm }: PaymentFormProps) => {
const stripe = useStripe();
const elements = useElements();

Expand All @@ -30,9 +27,7 @@ export const PaymentForm = ({ plan, period, onConfirm }: PaymentFormProps) => {
) => {
event.preventDefault();

const priceId =
period === "month" ? plan.monthlyPrice?.id : plan.yearlyPrice?.id;
if (!api || !stripe || !elements || !priceId) {
if (!api || !stripe || !elements) {
return;
}

Expand Down Expand Up @@ -77,28 +72,6 @@ export const PaymentForm = ({ plan, period, onConfirm }: PaymentFormProps) => {
overflowY: "auto",
}}
>
<Box $width="100%" $marginBottom="1.5rem">
<Text $size={18}>Add payment method</Text>
</Box>

<Flex
$flexDirection="column"
$gap="1.5rem"
$width="100%"
$marginBottom="1.5rem"
>
<LinkAuthenticationElement
id="link-authentication-element"
// Access the email value like so:
// onChange={(event) => {
// setEmail(event.value.email);
// }}
//
// Prefill the email field like so:
// options={{defaultValues: {email: 'foo@bar.com'}}}
/>
</Flex>

<Box $marginBottom="1.5rem">
<PaymentElement id="payment-element" />
</Box>
Expand Down
139 changes: 61 additions & 78 deletions components/src/components/elements/plan-manager/PlanManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,85 +90,68 @@ export const PlanManager = forwardRef<
}, [data.company, data.activePlans]);

return (
<div ref={ref} className={className}>
<Flex
$flexDirection="column"
$gap="0.75rem"
{...(canChangePlan && { $margin: "0 0 0.5rem" })}
>
{props.header.isVisible && currentPlan && (
<Flex
$justifyContent="space-between"
$alignItems="center"
$gap="1rem"
$width="100%"
{...(canChangePlan && { $margin: "0 0 1.5rem" })}
>
<div>
<Box $margin="0 0 0.75rem">
<Text
$font={
theme.typography[props.header.title.fontStyle].fontFamily
}
$size={
theme.typography[props.header.title.fontStyle].fontSize
}
$weight={
theme.typography[props.header.title.fontStyle].fontWeight
}
$color={theme.typography[props.header.title.fontStyle].color}
$lineHeight={1}
>
{currentPlan.name}
</Text>
</Box>

{props.header.description.isVisible &&
currentPlan.description && (
<Text
$font={
theme.typography[props.header.description.fontStyle]
.fontFamily
}
$size={
theme.typography[props.header.description.fontStyle]
.fontSize
}
$weight={
theme.typography[props.header.description.fontStyle]
.fontWeight
}
$color={
theme.typography[props.header.description.fontStyle].color
}
>
{currentPlan.description}
</Text>
)}
</div>
<Flex ref={ref} className={className} $flexDirection="column" $gap="2rem">
{props.header.isVisible && currentPlan && (
<Flex
$justifyContent="space-between"
$alignItems="center"
$width="100%"
>
<Flex $flexDirection="column" $gap="1rem">
<Text
as={Box}
$font={theme.typography[props.header.title.fontStyle].fontFamily}
$size={theme.typography[props.header.title.fontStyle].fontSize}
$weight={
theme.typography[props.header.title.fontStyle].fontWeight
}
$color={theme.typography[props.header.title.fontStyle].color}
$lineHeight={1}
>
{currentPlan.name}
</Text>

{props.header.price.isVisible &&
typeof currentPlan.planPrice === "number" &&
currentPlan.planPeriod && (
<Text
$font={
theme.typography[props.header.price.fontStyle].fontFamily
}
$size={
theme.typography[props.header.price.fontStyle].fontSize
}
$weight={
theme.typography[props.header.price.fontStyle].fontWeight
}
$color={theme.typography[props.header.price.fontStyle].color}
>
{formatCurrency(currentPlan.planPrice)}/
{currentPlan.planPeriod}
</Text>
)}
{props.header.description.isVisible && currentPlan.description && (
<Text
as={Box}
$font={
theme.typography[props.header.description.fontStyle]
.fontFamily
}
$size={
theme.typography[props.header.description.fontStyle].fontSize
}
$weight={
theme.typography[props.header.description.fontStyle]
.fontWeight
}
$color={
theme.typography[props.header.description.fontStyle].color
}
>
{currentPlan.description}
</Text>
)}
</Flex>
)}
</Flex>

{props.header.price.isVisible &&
typeof currentPlan.planPrice === "number" &&
currentPlan.planPeriod && (
<Text
$font={
theme.typography[props.header.price.fontStyle].fontFamily
}
$size={theme.typography[props.header.price.fontStyle].fontSize}
$weight={
theme.typography[props.header.price.fontStyle].fontWeight
}
$color={theme.typography[props.header.price.fontStyle].color}
>
{formatCurrency(currentPlan.planPrice)}/{currentPlan.planPeriod}
</Text>
)}
</Flex>
)}

{canChangePlan && props.callToAction.isVisible && (
<StyledButton
Expand All @@ -185,6 +168,6 @@ export const PlanManager = forwardRef<
{canChangePlan &&
layout === "checkout" &&
createPortal(<CheckoutDialog />, portal || document.body)}
</div>
</Flex>
);
});
1 change: 1 addition & 0 deletions components/src/components/elements/plan-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./PaymentForm";
export * from "./PlanManager";
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const UpcomingBill = forwardRef<
<Flex
$justifyContent="space-between"
$alignItems="center"
$margin="0 0 0.75rem"
$margin="0 0 1rem"
>
<Text
$font={theme.typography[props.header.fontStyle].fontFamily}
Expand Down
9 changes: 6 additions & 3 deletions components/src/components/ui/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ export const Modal = ({ children, size = "auto", onClose }: ModalProps) => {
$flexDirection="column"
$overflow="hidden"
{...(size === "auto"
? { $width: "min-content", $height: "min-content" }
? { $width: "fit-content", $height: "fit-content" }
: {
$width: "100%",
$height: "100%",
$maxWidth: "1356px",
...(size === "lg"
? { $height: "100%" }
: { $height: "fit-content" }),
$maxWidth:
size === "sm" ? "480px" : size === "md" ? "688px" : "1356px",
$maxHeight: "860px",
})}
$backgroundColor={theme.card.background}
Expand Down
13 changes: 12 additions & 1 deletion components/src/components/ui/text/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export interface TextProps extends ComponentProps {
$lineHeight?: ComponentProps["$lineHeight"];
}

export const Text = styled.span<TextProps>`
export const Text = styled.span.attrs(({ onClick }) => ({
...(onClick && { tabIndex: 0 }),
}))<TextProps>`
font-family: ${({ $font = "Inter" }) => `${$font}, sans-serif`};
font-size: ${({ $size = 16 }) =>
typeof $size === "number" ? `${$size / TEXT_BASE_SIZE}rem` : $size};
Expand All @@ -28,4 +30,13 @@ export const Text = styled.span<TextProps>`
outline: 2px solid ${({ theme }) => theme.primary};
outline-offset: 2px;
}
${({ onClick }) =>
onClick &&
css`
&:hover {
cursor: pointer;
text-decoration: underline;
}
`}
`;

0 comments on commit 591fe20

Please sign in to comment.