24 lines
809 B
TypeScript

'use client';
import { getStepsReducer } from './reducer';
import { type Steps } from './types';
import { useProfileQuery } from '@/hooks/profile';
import { useReducer, useState } from 'react';
export function useEntityState() {
const [entityId, setEntityId] = useState<null | string>(null);
return { entityId, setEntityId };
}
export function useStep() {
const { data: profile } = useProfileQuery();
const stepsReducer = getStepsReducer(profile);
const [state, dispatch] = useReducer(stepsReducer, { step: 'master-select' });
const setStep = (payload: Steps) => dispatch({ payload, type: 'SET_STEP' });
const nextStep = () => dispatch({ type: 'NEXT_STEP' });
const previousStep = () => dispatch({ type: 'PREV_STEP' });
return { nextStep, prevStep: previousStep, setStep, ...state };
}