Skip to content

Commit 6e79e89

Browse files
committed
feat: add authenticated routes
1 parent 50bdd39 commit 6e79e89

File tree

19 files changed

+151
-70
lines changed

19 files changed

+151
-70
lines changed
File renamed without changes.
File renamed without changes.

src/components/CheckoutStepper.tsx renamed to src/components/Stepper/CheckoutStepper.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import { Stepper } from '@openedx/paragon';
22
import { Navigate, useParams } from 'react-router-dom';
33

4-
import PlanDetails from '@/components/PlanDetails';
5-
import AccountDetails from '@/components/AccountDetails';
4+
import {
5+
BuildTrial,
6+
CreateAccount,
7+
CreateAccessLink,
8+
StartTrial,
9+
Success,
10+
} from '@/components/Stepper/Steps';
611

712
const Steps: React.FC = () => (
813
<div className="py-4">
9-
<PlanDetails />
10-
<AccountDetails />
14+
<BuildTrial />
15+
<CreateAccount />
16+
<CreateAccessLink />
17+
<StartTrial />
18+
<Success />
1119
</div>
1220
);
1321

1422
const CheckoutStepper: React.FC = () => {
1523
const { step } = useParams<{ step: Step }>();
1624
if (!step) {
17-
return <Navigate to="plan" />;
25+
return <Navigate to="build-trial" />;
1826
}
1927
return (
2028
<Stepper activeKey={step}>

src/components/StepCounter.tsx renamed to src/components/Stepper/StepCounter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useParams } from 'react-router';
22
import { FormattedMessage } from '@edx/frontend-platform/i18n';
33

4-
import { steps } from '@/constants';
4+
import { steps } from '@/components/Stepper/constants';
55

66
const StepCounter: React.FC = () => {
77
const { step } = useParams<{ step: Step }>();

src/components/PlanDetails.tsx renamed to src/components/Stepper/Steps/BuildTrial.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import { Controller, useForm } from 'react-hook-form';
77
import { zodResolver } from '@hookform/resolvers/zod';
88
import { FormattedMessage } from '@edx/frontend-platform/i18n';
99

10-
import { PlanSchema, steps } from '@/constants';
11-
import Field, { useIsFieldInvalid, useIsFieldValid } from '@/components/Field';
12-
import StepCounter from '@/components/StepCounter';
10+
import { BuildTrialSchema, steps } from '@/components/Stepper/constants';
11+
import Field, { useIsFieldInvalid, useIsFieldValid } from '@/components/FormFields/Field';
12+
import StepCounter from '@/components/Stepper/StepCounter';
1313
import useCheckoutFormStore from '@/hooks/useCheckoutFormStore';
1414

15-
const PlanDetails: React.FC = () => {
16-
const planFormData = useCheckoutFormStore((state) => state.formData.plan);
15+
const BuildTrial: React.FC = () => {
16+
const planFormData = useCheckoutFormStore((state) => state.formData.buildTrial);
1717
const setFormData = useCheckoutFormStore((state) => state.setFormData);
1818
const navigate = useNavigate();
1919

20-
const form = useForm<PlanData>({
20+
const form = useForm<BuildTrial>({
2121
mode: 'onTouched',
22-
resolver: zodResolver(PlanSchema),
22+
resolver: zodResolver(BuildTrialSchema),
2323
defaultValues: planFormData,
2424
});
2525
const {
@@ -28,9 +28,9 @@ const PlanDetails: React.FC = () => {
2828
formState: { isValid },
2929
} = form;
3030

31-
const onSubmit = (data: PlanData) => {
32-
setFormData('plan', data);
33-
navigate('/checkout/account');
31+
const onSubmit = (data: BuildTrial) => {
32+
setFormData('buildTrial', data);
33+
navigate('/create-account');
3434
};
3535

3636
const isFieldValid = useIsFieldValid(form);
@@ -61,6 +61,7 @@ const PlanDetails: React.FC = () => {
6161
registerOptions={{
6262
validate: () => {
6363
// Check react-hook-form docs for more info...
64+
console.log('validating users');
6465
},
6566
}}
6667
autoFocus
@@ -86,7 +87,7 @@ const PlanDetails: React.FC = () => {
8687
ariaLabelledby="planTypeLabel"
8788
value={value}
8889
onChange={(e) => {
89-
setFormData('plan', {
90+
setFormData('buildTrial', {
9091
...planFormData,
9192
planType: e.target.value as PlanType,
9293
});
@@ -150,4 +151,4 @@ const PlanDetails: React.FC = () => {
150151
);
151152
};
152153

153-
export default PlanDetails;
154+
export default BuildTrial;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Stepper } from '@openedx/paragon';
2+
import { steps } from '@/components/Stepper/constants';
3+
4+
const CreateAccessLink = () => {
5+
const eventKey = steps[2];
6+
return (
7+
<Stepper.Step eventKey={eventKey} title="Create Access Link">
8+
Create Access Link
9+
</Stepper.Step>
10+
);
11+
};
12+
13+
export default CreateAccessLink;

src/components/AccountDetails.tsx renamed to src/components/Stepper/Steps/CreateAccount.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { zodResolver } from '@hookform/resolvers/zod';
1414
import slugify from 'slugify';
1515
import classNames from 'classnames';
1616

17-
import { AccountSchema, PlanSchema, steps } from '@/constants';
18-
import Field from '@/components/Field';
19-
import StepCounter from '@/components/StepCounter';
17+
import { CreateAccountSchema, BuildTrialSchema, steps } from '@/components/Stepper/constants';
18+
import Field from '@/components/FormFields/Field';
19+
import StepCounter from '@/components/Stepper/StepCounter';
2020
import useCheckoutFormStore from '@/hooks/useCheckoutFormStore';
2121

2222
interface StatefulPurchaseButtonProps {
@@ -73,7 +73,7 @@ interface OrganizatonEmailHelpTextProps {
7373
isInvalid: boolean;
7474
}
7575

76-
const OrganizatonEmailHelpText: React.FC<OrganizatonEmailHelpTextProps> = ({ isInvalid }) => {
76+
const OrganizationEmailHelpText: React.FC<OrganizatonEmailHelpTextProps> = ({ isInvalid }) => {
7777
if (isInvalid) {
7878
return null;
7979
}
@@ -88,19 +88,19 @@ const OrganizatonEmailHelpText: React.FC<OrganizatonEmailHelpTextProps> = ({ isI
8888
);
8989
};
9090

91-
OrganizatonEmailHelpText.propTypes = {
91+
OrganizationEmailHelpText.propTypes = {
9292
isInvalid: PropTypes.bool.isRequired,
9393
};
9494

95-
const AccountDetails: React.FC = () => {
95+
const CreateAccount: React.FC = () => {
9696
const intl = useIntl();
9797
const navigate = useNavigate();
98-
const planFormData = useCheckoutFormStore((state) => state.formData.plan);
99-
const accountFormData = useCheckoutFormStore((state) => state.formData.account);
98+
const planFormData = useCheckoutFormStore((state) => state.formData.buildTrial);
99+
const accountFormData = useCheckoutFormStore((state) => state.formData.createAccount);
100100

101101
useEffect(() => {
102-
if (!planFormData || !PlanSchema.safeParse(planFormData).success) {
103-
navigate('/checkout/plan');
102+
if (!planFormData || !BuildTrialSchema.safeParse(planFormData).success) {
103+
navigate('/build-trial');
104104
}
105105
}, [planFormData, navigate]);
106106

@@ -127,12 +127,12 @@ const AccountDetails: React.FC = () => {
127127
}, [isEditingSlug]);
128128

129129
const handlePrevious = () => {
130-
navigate('/checkout/plan');
130+
navigate('/build-trial');
131131
};
132132

133-
const onSubmit = (data: AccountData) => {
134-
setFormData('account', data);
135-
navigate('/checkout/confirmation');
133+
const onSubmit = (data: CreateAccount) => {
134+
setFormData('createAccount', data);
135+
navigate('/create-access-link');
136136
};
137137

138138
const orgName = watch('orgName');
@@ -198,7 +198,7 @@ const AccountDetails: React.FC = () => {
198198
placeholder="[email protected]"
199199
defaultValue={accountFormData?.orgEmail}
200200
controlClassName="mr-0"
201-
controlFooterNode={OrganizatonEmailHelpText}
201+
controlFooterNode={OrganizationEmailHelpText}
202202
/>
203203
<Field
204204
form={form}
@@ -389,4 +389,4 @@ const AccountDetails: React.FC = () => {
389389
);
390390
};
391391

392-
export default AccountDetails;
392+
export default CreateAccount;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { steps } from '@/components/Stepper/constants';
2+
import { Stepper } from '@openedx/paragon';
3+
4+
const StartTrial = () => {
5+
const eventKey = steps[3];
6+
return (
7+
<Stepper.Step eventKey={eventKey} title="Create Trial">
8+
Start Trial
9+
</Stepper.Step>
10+
);
11+
};
12+
13+
export default StartTrial;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { steps } from '@/components/Stepper/constants';
2+
import { Stepper } from '@openedx/paragon';
3+
4+
const Success = () => {
5+
const eventKey = steps[4];
6+
return (
7+
<Stepper.Step eventKey={eventKey} title="Success">
8+
Success
9+
</Stepper.Step>
10+
);
11+
};
12+
13+
export default Success;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { default as BuildTrial } from './BuildTrial';
2+
export { default as CreateAccount } from './CreateAccount';
3+
export { default as CreateAccessLink } from './CreateAccessLink';
4+
export { default as StartTrial } from './StartTrial';
5+
export { default as Success } from './Success';

0 commit comments

Comments
 (0)