-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split reusable hooks into dedicated modules Refactored hooks for Department, Employee, and Product into separate modules under the `hooks` folder for better modularity and maintainability. Updated imports in affected components to reflect the new structure. Removed the original consolidated `hooks.ts` file.
- Loading branch information
Showing
8 changed files
with
154 additions
and
146 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
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
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,52 @@ | ||
import {useState} from "react"; | ||
import { | ||
DepartmentIdType, | ||
DepartmentType, | ||
LowerType, | ||
SlitYnType | ||
} from "../../../models"; | ||
import {DepartmentService, DepartmentServiceType} from "../../../services/department.ts"; | ||
import {PageNationType} from "../../../views/application/PageNation.tsx"; | ||
import {useFetchEntities} from "../../application/hooks.ts"; | ||
|
||
export const useDepartment = () => { | ||
const initialDepartment = { | ||
departmentId: {deptCode: {value: ""}, departmentStartDate: {value: ""}}, | ||
endDate: {value: ""}, | ||
departmentName: "", | ||
layer: 0, | ||
path: {value: ""}, | ||
lowerType: LowerType.NO, | ||
slitYn: SlitYnType.NO, | ||
employees: [], | ||
checked: false | ||
}; | ||
|
||
const [departments, setDepartments] = useState<DepartmentType[]>([]); | ||
const [newDepartment, setNewDepartment] = useState<DepartmentType>(initialDepartment); | ||
const [searchDepartmentId, setSearchDepartmentId] = useState<DepartmentIdType>({ | ||
deptCode: {value: ""}, | ||
departmentStartDate: {value: ""} | ||
}); | ||
const departmentService = DepartmentService(); | ||
|
||
return { | ||
initialDepartment, | ||
departments, | ||
newDepartment, | ||
setNewDepartment, | ||
searchDepartmentId, | ||
setSearchDepartmentId, | ||
setDepartments, | ||
departmentService, | ||
} | ||
} | ||
|
||
export const useFetchDepartments = ( | ||
setLoading: (loading: boolean) => void, | ||
setList: (list: DepartmentType[]) => void, | ||
setPageNation: (pageNation: PageNationType) => void, | ||
setError: (error: string) => void, | ||
showErrorMessage: (message: string, callback: (error: string) => void) => void, | ||
service: DepartmentServiceType | ||
) => useFetchEntities(setLoading, setList, setPageNation, setError, showErrorMessage, service, "部門情報の取得に失敗しました:"); |
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,89 @@ | ||
import {useState} from "react"; | ||
import { | ||
EmployeeType, | ||
LowerType, | ||
SlitYnType | ||
} from "../../../models"; | ||
import {EmployeeService, EmployeeServiceType} from "../../../services/employee.ts"; | ||
import {PageNationType} from "../../../views/application/PageNation.tsx"; | ||
import {useFetchEntities} from "../../application/hooks.ts"; | ||
|
||
export const useEmployee = () => { | ||
const initialEmployee: EmployeeType = { | ||
empCode: {value: ""}, | ||
empName: { | ||
firstName: "", | ||
lastName: "", | ||
firstNameKana: "", | ||
lastNameKana: "" | ||
}, | ||
loginPassword: "", | ||
tel: { | ||
value: "", | ||
areaCode: "", | ||
localExchange: "", | ||
subscriberNumber: "" | ||
}, | ||
fax: { | ||
value: "", | ||
areaCode: "", | ||
localExchange: "", | ||
subscriberNumber: "" | ||
}, | ||
occuCode: { | ||
value: "" | ||
}, | ||
approvalCode: "", | ||
department: { | ||
departmentId: {deptCode: {value: ""}, departmentStartDate: {value: ""}}, | ||
endDate: {value: ""}, | ||
departmentName: "", | ||
layer: 0, | ||
path: {value: ""}, | ||
lowerType: LowerType.NO, | ||
slitYn: SlitYnType.NO, | ||
employees: [], | ||
checked: false | ||
}, | ||
user: { | ||
userId: {value: ""}, | ||
name: { | ||
firstName: "", | ||
lastName: "" | ||
}, | ||
password: { | ||
value: "" | ||
}, | ||
roleName: "" | ||
}, | ||
addFlag: false, | ||
deleteFlag: false, | ||
checked: false | ||
}; | ||
|
||
const [employees, setEmployees] = useState<EmployeeType[]>([]); | ||
const [newEmployee, setNewEmployee] = useState<EmployeeType>(initialEmployee); | ||
const [searchEmployeeCode, setSearchEmployeeCode] = useState<string>(""); | ||
|
||
const employeeService = EmployeeService(); | ||
|
||
return { | ||
initialEmployee, | ||
employees, | ||
newEmployee, | ||
setNewEmployee, | ||
setEmployees, | ||
searchEmployeeCode, | ||
setSearchEmployeeCode, | ||
employeeService, | ||
}; | ||
} | ||
|
||
export const useFetchEmployees = ( | ||
setLoading: (loading: boolean) => void, | ||
setList: (list: EmployeeType[]) => void, | ||
setPageNation: (pageNation: PageNationType) => void, | ||
setError: (error: string) => void, | ||
showErrorMessage: (message: string, callback: (error: string) => void) => void, | ||
service: EmployeeServiceType | ||
) => useFetchEntities(setLoading, setList, setPageNation, setError, showErrorMessage, service, "社員情報の取得に失敗しました:"); |
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,3 @@ | ||
export * from './department'; | ||
export * from './employee'; | ||
export * from './product'; |
142 changes: 6 additions & 136 deletions
142
app/frontend/src/components/master/hooks.ts → ...nd/src/components/master/hooks/product.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