From af2b169926dd8266f9578c17097f29ebe3c280e1 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Thu, 26 Oct 2023 20:43:50 +0700 Subject: [PATCH] Fix code style format --- .../src/components/Dialog/index.tsx | 4 ++++ hotel-management/src/hooks/useForm.ts | 21 +++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/hotel-management/src/components/Dialog/index.tsx b/hotel-management/src/components/Dialog/index.tsx index 1c9c23f..8e73da6 100644 --- a/hotel-management/src/components/Dialog/index.tsx +++ b/hotel-management/src/components/Dialog/index.tsx @@ -1,5 +1,9 @@ import { forwardRef } from 'react'; + +// Components import { IDialogProps } from '../../globals/interfaces'; + +// Styled import { StyledBody, StyledDialog, StyledTitle } from './styled'; const Dialog = forwardRef((props, ref) => { diff --git a/hotel-management/src/hooks/useForm.ts b/hotel-management/src/hooks/useForm.ts index 54e4ad0..74be96e 100644 --- a/hotel-management/src/hooks/useForm.ts +++ b/hotel-management/src/hooks/useForm.ts @@ -1,4 +1,6 @@ import { useState, useEffect, useCallback, ChangeEvent } from 'react'; + +// Utils import { ERROR, VALUE, @@ -6,6 +8,8 @@ import { isObject, isRequired, } from '../helpers/utils'; + +// Types import { TKeyValue, TValidator } from '../globals/types'; /** @@ -16,23 +20,19 @@ import { TKeyValue, TValidator } from '../globals/types'; * @param submitFormCallback function to be execute during form submission. * @returns */ -function useForm( +const useForm = ( stateSchema = {}, stateValidatorSchema = {} as TValidator, submitFormCallback: (values: TKeyValue) => void, -) { - const [state, setStateSchema] = useState(stateSchema); - - const [values, setValues] = useState(getPropValues(state, VALUE)); - const [errors, setErrors] = useState(getPropValues(state, ERROR)); - const [dirty, setDirty] = useState(getPropValues(state)); - +) => { + const [values, setValues] = useState(getPropValues(stateSchema, VALUE)); + const [errors, setErrors] = useState(getPropValues(stateSchema, ERROR)); + const [dirty, setDirty] = useState(getPropValues(stateSchema)); const [disable, setDisable] = useState(true); const [isDirty, setIsDirty] = useState(false); // Get a local copy of stateSchema useEffect(() => { - setStateSchema(stateSchema); setDisable(true); // Disable button in initial render. setInitialErrorState(); }, []); // eslint-disable-line @@ -118,7 +118,6 @@ function useForm( // before calling the submit callback function if (!validateErrorState()) { submitFormCallback(values); - console.log(values); } }, [validateErrorState, submitFormCallback, values], @@ -134,6 +133,6 @@ function useForm( setErrors, dirty, }; -} +}; export default useForm;