2025-04-16 12:45:01 +03:00

20 lines
648 B
TypeScript

'use client';
import { reducer } from './reducer';
import { type Steps } from './types';
import { useReducer, useState } from 'react';
export function useEntityState() {
const [entityId, setEntityId] = useState<null | string>(null);
return { entityId, setEntityId };
}
export function useStep() {
const [state, dispatch] = useReducer(reducer, { 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 };
}