|
@@ -1,4 +1,4 @@
|
|
|
-import { memo, useRef } from 'react';
|
|
|
|
|
|
|
+import { memo, useEffect } from 'react';
|
|
|
|
|
|
|
|
import { Form } from 'antd';
|
|
import { Form } from 'antd';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
@@ -10,7 +10,6 @@ import PayMethodCard from './components/PayMethodCard';
|
|
|
import PlanCard from './components/PlanCard';
|
|
import PlanCard from './components/PlanCard';
|
|
|
import UserInfo from './components/UserInfo';
|
|
import UserInfo from './components/UserInfo';
|
|
|
import { useAction } from './useAction';
|
|
import { useAction } from './useAction';
|
|
|
-import { usePlanCardsHeightSync } from './usePlanCardsHeightSync';
|
|
|
|
|
import { useService } from './useService';
|
|
import { useService } from './useService';
|
|
|
import type { Plan } from './useService';
|
|
import type { Plan } from './useService';
|
|
|
|
|
|
|
@@ -20,21 +19,14 @@ export interface PlanSelectorProps {
|
|
|
value?: string;
|
|
value?: string;
|
|
|
onChange?: (planId: string) => void;
|
|
onChange?: (planId: string) => void;
|
|
|
plans: Plan[];
|
|
plans: Plan[];
|
|
|
- planCardsContainerRef: React.RefObject<HTMLDivElement | null>;
|
|
|
|
|
isMobile: boolean;
|
|
isMobile: boolean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function PlanSelector({
|
|
|
|
|
- value,
|
|
|
|
|
- onChange,
|
|
|
|
|
- plans,
|
|
|
|
|
- planCardsContainerRef,
|
|
|
|
|
- isMobile,
|
|
|
|
|
-}: PlanSelectorProps) {
|
|
|
|
|
|
|
+function PlanSelector({ value, onChange, plans, isMobile }: PlanSelectorProps) {
|
|
|
return (
|
|
return (
|
|
|
<div
|
|
<div
|
|
|
- ref={planCardsContainerRef as React.RefObject<HTMLDivElement>}
|
|
|
|
|
data-count={plans.length}
|
|
data-count={plans.length}
|
|
|
|
|
+ style={{ gridAutoRows: '1fr' }}
|
|
|
className={
|
|
className={
|
|
|
isMobile
|
|
isMobile
|
|
|
? 'flex-col-c gap-5'
|
|
? 'flex-col-c gap-5'
|
|
@@ -90,7 +82,6 @@ const Pricing = memo(() => {
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
const { isMobile } = useResponsive();
|
|
const { isMobile } = useResponsive();
|
|
|
const [form] = Form.useForm<{ planId: string; payMethod: string }>();
|
|
const [form] = Form.useForm<{ planId: string; payMethod: string }>();
|
|
|
- const planCardsContainerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const { plans, payMethods } = useService();
|
|
const { plans, payMethods } = useService();
|
|
|
const { handlePayNow } = useAction();
|
|
const { handlePayNow } = useAction();
|
|
|
|
|
|
|
@@ -99,7 +90,13 @@ const Pricing = memo(() => {
|
|
|
const selectedPlan = plans.find((p) => p.id === planId) ?? null;
|
|
const selectedPlan = plans.find((p) => p.id === planId) ?? null;
|
|
|
const selectedPayMethod = payMethod ?? null;
|
|
const selectedPayMethod = payMethod ?? null;
|
|
|
|
|
|
|
|
- usePlanCardsHeightSync(planCardsContainerRef, isMobile, plans.length);
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (plans.length === 0) return;
|
|
|
|
|
+ const defaultPlan = plans.find((p) => p.isDefault);
|
|
|
|
|
+ if (defaultPlan) {
|
|
|
|
|
+ form.setFieldsValue({ planId: defaultPlan.id });
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [plans, form]);
|
|
|
|
|
|
|
|
const onFinish = (values: { planId: string; payMethod: string }) => {
|
|
const onFinish = (values: { planId: string; payMethod: string }) => {
|
|
|
const plan = plans.find((p) => p.id === values.planId);
|
|
const plan = plans.find((p) => p.id === values.planId);
|
|
@@ -142,11 +139,7 @@ const Pricing = memo(() => {
|
|
|
]}
|
|
]}
|
|
|
className="mb-0 [&_.ant-form-item-explain]:mt-3"
|
|
className="mb-0 [&_.ant-form-item-explain]:mt-3"
|
|
|
>
|
|
>
|
|
|
- <PlanSelector
|
|
|
|
|
- plans={plans}
|
|
|
|
|
- planCardsContainerRef={planCardsContainerRef}
|
|
|
|
|
- isMobile={isMobile}
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ <PlanSelector plans={plans} isMobile={isMobile} />
|
|
|
</Form.Item>
|
|
</Form.Item>
|
|
|
</div>
|
|
</div>
|
|
|
<div className="flex flex-col gap-4 mt-1">
|
|
<div className="flex flex-col gap-4 mt-1">
|