Skip to content

Commit

Permalink
convert React Checkout/Hook/useStep component to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo Cherblanc authored and Lucanis committed Jan 17, 2024
1 parent 6732978 commit 3e37290
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
21 changes: 21 additions & 0 deletions templates/frontOffice/modern/assets/js/types/checkout.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {
Address,
CheckoutAddress,
CustomerState
} from '@components/React/Checkout/type';
import { DeliveryModule, PickupAddress } from './common';

export type CheckoutPageType = {
id: number;
slug: string;
Expand Down Expand Up @@ -31,3 +38,17 @@ export declare type CheckoutResponse = {
acceptedTermsAndConditions: boolean;
isComplete: boolean;
};

export type Checkout = {
step: number;
customer: CustomerState;
deliveryAddressId: CheckoutAddress['id'] | Address['id'] | null;
billingAddressId: CheckoutAddress['id'] | Address['id'] | null;
needValidate: CheckoutRequest['needValidate'];
deliveryModule: DeliveryModule | null;
paymentModuleId: number | null;
deliveryModuleOptionCode: 'string' | null;
pickupAddress: PickupAddress | null;
acceptedTermsAndConditions: boolean;
isComplete: boolean;
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { useState, useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { setCheckoutStep } from '@js/redux/modules/checkout';
export default function useStep(checkout) {
import { Checkout } from '@js/types/checkout.types';
export default function useStep(checkout: Checkout) {
const [step, setStep] = useState(1);
const dispatch = useDispatch();
const { mode: selectedMode, phoneCheck = true, checkoutStep } = useSelector((state) => state.checkout);
const {
mode: selectedMode,
phoneCheck = true,
checkoutStep
} = useSelector((state: any) => state.checkout);

useEffect(() => {
if (checkoutStep) {
setStep(checkoutStep);
}
else if (
} else if (
selectedMode !== null &&
checkout?.deliveryModuleOptionCode &&
checkout?.deliveryAddressId &&
Expand Down Expand Up @@ -58,7 +62,6 @@ export default function useStep(checkout) {
dispatch(setCheckoutStep(3));
} else if (selectedMode !== null) {
dispatch(setCheckoutStep(3));

} else {
setStep(1);
}
Expand Down

0 comments on commit 3e37290

Please sign in to comment.