diff --git a/apps/web/components/orders/components/service-select.tsx b/apps/web/components/orders/components/service-select.tsx index 11ae274..c316af9 100644 --- a/apps/web/components/orders/components/service-select.tsx +++ b/apps/web/components/orders/components/service-select.tsx @@ -16,13 +16,34 @@ export function ServiceSelect() { ); } -function ServiceCard({ name }: Readonly) { +function ServiceCard({ documentId, name }: Readonly) { + const { serviceId, setServiceId } = use(OrderContext); + + const selected = serviceId === documentId; + + function handleOnSelect() { + setServiceId(documentId); + } + return ( -
+
+ ); } diff --git a/apps/web/components/orders/components/submit-button.tsx b/apps/web/components/orders/components/submit-button.tsx index 8ca1c44..0cdcea9 100644 --- a/apps/web/components/orders/components/submit-button.tsx +++ b/apps/web/components/orders/components/submit-button.tsx @@ -4,7 +4,7 @@ import { Button } from '@repo/ui/components/ui/button'; import { use } from 'react'; export function SubmitButton() { - const { customerId, nextStep, step } = use(OrderContext); + const { nextStep, step } = use(OrderContext); function handleOnClick() { if (step !== 'success') { @@ -12,7 +12,7 @@ export function SubmitButton() { } } - const disabled = step === 'customer-select' && !customerId; + const disabled = useButtonDisabled(); return ( ); } + +function useButtonDisabled() { + const { customerId, serviceId, step } = use(OrderContext); + + return (step === 'customer-select' && !customerId) || (step === 'service-select' && !serviceId); +} diff --git a/apps/web/context/order.tsx b/apps/web/context/order.tsx index a184066..3fead74 100644 --- a/apps/web/context/order.tsx +++ b/apps/web/context/order.tsx @@ -7,7 +7,9 @@ type ContextType = { customerId: null | string; nextStep: () => void; prevStep: () => void; + serviceId: null | string; setCustomerId: (customerId: string) => void; + setServiceId: (serviceId: string) => void; setStep: (step: Steps) => void; step: Steps; }; @@ -44,9 +46,9 @@ function stepsReducer(state: State, action: Action): State { } } -function useCustomerState() { - const [customerId, setCustomerId] = useState(null); - return { customerId, setCustomerId }; +function useEntityState() { + const [entityId, setEntityId] = useState(null); + return { entityId, setEntityId }; } function useStep() { @@ -62,7 +64,9 @@ function useStep() { export const OrderContext = createContext({} as ContextType); export function OrderContextProvider({ children }: Readonly) { - const { customerId, setCustomerId } = useCustomerState(); + const { entityId: customerId, setEntityId: setCustomerId } = useEntityState(); + const { entityId: serviceId, setEntityId: setServiceId } = useEntityState(); + const { nextStep, prevStep, setStep, step } = useStep(); const value = useMemo( @@ -70,11 +74,13 @@ export function OrderContextProvider({ children }: Readonly) customerId, nextStep, prevStep, + serviceId, setCustomerId, + setServiceId, setStep, step, }), - [customerId, nextStep, prevStep, setCustomerId, setStep, step], + [customerId, nextStep, prevStep, serviceId, setCustomerId, setServiceId, setStep, step], ); return {children};