-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 패키지 구조 변경 * feat: useForm hook 구현 * refactor: 중복 로직 리팩토링
- Loading branch information
Showing
151 changed files
with
499 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default { | ||
// other rules... | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: ['./tsconfig.json', './tsconfig.node.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
}; | ||
``` | ||
|
||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` | ||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default { | ||
// other rules... | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: ['./tsconfig.json', './tsconfig.node.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
}; | ||
``` | ||
|
||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` | ||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...minMemberAddModal/AdminMemberAddModal.tsx → ...minMemberAddModal/AdminMemberAddModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
frontend-monorepo/packages/hanglog-admin/src/adminMember/hooks/useAddAdminMemberForm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { AdminMemberFormData } from '@type/adminMember'; | ||
|
||
import { useForm } from '@hooks/useForm'; | ||
|
||
import { isEmptyString, isValidPassword } from '@utils/validator'; | ||
|
||
import { useAddAdminMemberMutation } from './useAddAdminMemberMutation'; | ||
|
||
interface useAddAdminMemberFormParams { | ||
onSuccess?: () => void; | ||
onError?: () => void; | ||
} | ||
|
||
export const useAddAdminMemberForm = ({ onSuccess, onError }: useAddAdminMemberFormParams) => { | ||
const addAdminMemberMutation = useAddAdminMemberMutation(); | ||
|
||
const initialValues: AdminMemberFormData = { | ||
username: '', | ||
adminType: 'ADMIN', | ||
password: '', | ||
confirmPassword: '', | ||
}; | ||
|
||
const validate = (values: AdminMemberFormData) => { | ||
return { | ||
username: isEmptyString(values.username.trim()), | ||
password: !isValidPassword(values.password.trim()), | ||
confirmPassword: values.password !== values.confirmPassword, | ||
}; | ||
}; | ||
|
||
const submitAction = ( | ||
values: AdminMemberFormData, | ||
onSuccess?: () => void, | ||
onError?: () => void | ||
) => { | ||
addAdminMemberMutation.mutate(values, { onSuccess, onError }); | ||
}; | ||
|
||
const { formValues, errors, updateInputValue, disableError, handleSubmit } = useForm( | ||
initialValues, | ||
validate, | ||
submitAction, | ||
{ onSuccess, onError } | ||
); | ||
|
||
const adjustedErrors = { | ||
isUsernameError: errors.username, | ||
isPasswordError: errors.password, | ||
isConfirmPasswordError: errors.confirmPassword, | ||
}; | ||
|
||
return { | ||
adminMemberInformation: formValues, | ||
errors: adjustedErrors, | ||
disableError, | ||
updateInputValue, | ||
handleSubmit, | ||
}; | ||
}; |
5 changes: 3 additions & 2 deletions
5
...rc/hooks/api/useAddAdminMemberMutation.ts → ...Member/hooks/useAddAdminMemberMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...dmin/src/hooks/api/useAdminMemberQuery.ts → .../adminMember/hooks/useAdminMemberQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...i/useUpdateAdminMemberPasswordMutation.ts → ...s/useUpdateAdminMemberPasswordMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
frontend-monorepo/packages/hanglog-admin/src/adminMember/hooks/useUpdatePasswordForm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { PasswordPatchData } from '@type/adminMember'; | ||
|
||
import { useForm } from '@hooks/useForm'; | ||
|
||
import { isEmptyString, isValidPassword } from '@utils/validator'; | ||
|
||
import { useUpdateAdminMemberPasswordMutation } from './useUpdateAdminMemberPasswordMutation'; | ||
|
||
interface useUpdatePasswordFormParams { | ||
adminMemberId: number; | ||
onSuccess?: () => void; | ||
onError?: () => void; | ||
} | ||
|
||
export interface PasswordFormData extends PasswordPatchData { | ||
confirmPassword: string; | ||
} | ||
|
||
export const useUpdatePasswordForm = ( | ||
{ adminMemberId, onSuccess, onError }: useUpdatePasswordFormParams | ||
) => { | ||
const updatePasswordMutation = useUpdateAdminMemberPasswordMutation(); | ||
|
||
const initialValues: PasswordFormData = { | ||
currentPassword: '', | ||
newPassword: '', | ||
confirmPassword: '', | ||
}; | ||
|
||
const validate = (values: PasswordFormData) => { | ||
return { | ||
currentPassword: isEmptyString(values.currentPassword.trim()), | ||
newPassword: !isValidPassword(values.newPassword.trim()), | ||
confirmPassword: values.newPassword !== values.confirmPassword, | ||
}; | ||
}; | ||
|
||
const submitAction = (values: PasswordFormData, onSuccess?: () => void, onError?: () => void) => { | ||
updatePasswordMutation.mutate( | ||
{ | ||
adminMemberId, | ||
currentPassword: values.currentPassword, | ||
newPassword: values.newPassword, | ||
}, | ||
{ onSuccess, onError } | ||
); | ||
}; | ||
|
||
const { formValues, errors, updateInputValue, disableError, handleSubmit } = useForm( | ||
initialValues, | ||
validate, | ||
submitAction, | ||
{ onSuccess, onError } | ||
); | ||
|
||
const adjustedErrors = { | ||
isCurrentPasswordError: errors.currentPassword, | ||
isNewPasswordError: errors.newPassword, | ||
isConfirmPasswordError: errors.confirmPassword, | ||
}; | ||
|
||
return { | ||
passwordFormData: formValues, | ||
errors: adjustedErrors, | ||
disableError, | ||
updateInputValue, | ||
handleSubmit, | ||
}; | ||
}; |
File renamed without changes.
11 changes: 6 additions & 5 deletions
11
...pages/AdminMemberPage/AdminMemberPage.tsx → ...src/adminMember/pages/AdminMemberPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ory/CategoryAddModal/CategoryAddModal.tsx → ...nts/CategoryAddModal/CategoryAddModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 65 additions & 0 deletions
65
frontend-monorepo/packages/hanglog-admin/src/category/hooks/useAddCategoryForm.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { CategoryData } from '@type/category'; | ||
|
||
import { useForm } from '@hooks/useForm'; | ||
|
||
import { isEmptyString, isEnglish, isInvalidCategoryId, isKorean } from '@utils/validator'; | ||
|
||
import { useAddCategoryMutation } from './useAddCategoryMutation'; | ||
import { useUpdateCategoryMutation } from './useUpdateCategoryMutation'; | ||
|
||
interface useAddCategoryFormParams { | ||
originalCategoryId?: number; | ||
initialData?: CategoryData; | ||
onSuccess?: () => void; | ||
onError?: () => void; | ||
} | ||
|
||
export const useAddCategoryForm = ( | ||
{ originalCategoryId, initialData, onSuccess, onError }: useAddCategoryFormParams | ||
) => { | ||
const addCategoryMutation = useAddCategoryMutation(); | ||
const updateCategoryMutation = useUpdateCategoryMutation(); | ||
|
||
const initialValues: CategoryData = initialData ?? { | ||
id: 0, | ||
engName: '', | ||
korName: '', | ||
}; | ||
|
||
const validate = (values: CategoryData) => { | ||
return { | ||
id: isInvalidCategoryId(values.id), | ||
engName: isEmptyString(values.engName.trim()) || !isEnglish(values.engName), | ||
korName: isEmptyString(values.korName.trim()) || !isKorean(values.korName), | ||
}; | ||
}; | ||
|
||
const submitAction = (values: CategoryData, onSuccess?: () => void, onError?: () => void) => { | ||
if (originalCategoryId !== undefined) { | ||
updateCategoryMutation.mutate({ ...values, id: originalCategoryId }, { onSuccess, onError }); | ||
} else { | ||
addCategoryMutation.mutate(values, { onSuccess, onError }); | ||
} | ||
}; | ||
|
||
const { formValues, errors, updateInputValue, disableError, handleSubmit } = useForm( | ||
initialValues, | ||
validate, | ||
submitAction, | ||
{ onSuccess, onError } | ||
); | ||
|
||
const adjustedErrors = { | ||
isIdError: errors.id, | ||
isEngNameError: errors.engName, | ||
isKorNameError: errors.korName, | ||
}; | ||
|
||
return { | ||
categoryInformation: formValues, | ||
errors: adjustedErrors, | ||
disableError, | ||
updateInputValue, | ||
handleSubmit, | ||
}; | ||
}; |
Oops, something went wrong.