|
|
|
@@ -1,22 +1,30 @@ |
|
|
|
import { |
|
|
|
Box, |
|
|
|
Grid, |
|
|
|
Stack, |
|
|
|
Table, |
|
|
|
TableBody, |
|
|
|
TableCell, |
|
|
|
TableContainer, |
|
|
|
TablePagination, |
|
|
|
TableRow, |
|
|
|
TextField, |
|
|
|
Typography, |
|
|
|
} from "@mui/material"; |
|
|
|
import { Dictionary } from "@types"; |
|
|
|
import { Contract, getContracts } from "api/contract"; |
|
|
|
import { PageID, TabID } from "codes/page"; |
|
|
|
import { FormProvider, RHFTextField } from "components/hook-form"; |
|
|
|
import { TableHeadCustom } from "components/table"; |
|
|
|
import { SearchConditionContextProvider } from "contexts/SearchConditionContext"; |
|
|
|
import useAPICall from "hooks/useAPICall"; |
|
|
|
import useBackDrop from "hooks/useBackDrop"; |
|
|
|
import useDashboard from "hooks/useDashBoard"; |
|
|
|
import useNavigateCustom from "hooks/useNavigateCustom"; |
|
|
|
import useSearchConditionContext from "hooks/useSearchConditionContext"; |
|
|
|
import useTable, { UseTableReturn } from "hooks/useTable"; |
|
|
|
import ContractTabs from "layouts/dashbord/tab/ContractTabs"; |
|
|
|
import { useEffect } from "react"; |
|
|
|
import { Contract } from "types/contract"; |
|
|
|
import { useForm } from "react-hook-form"; |
|
|
|
import { getPath } from "routes/path"; |
|
|
|
|
|
|
|
export default function ContractList() { |
|
|
|
const { setHeaderTitle, setTabs } = useDashboard( |
|
|
|
@@ -24,42 +32,20 @@ export default function ContractList() { |
|
|
|
TabID.NONE |
|
|
|
); |
|
|
|
|
|
|
|
const table = useTable<Contract>(); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
setHeaderTitle("契約者一覧"); |
|
|
|
setTabs(<ContractTabs />); |
|
|
|
setTabs(null); |
|
|
|
}, []); |
|
|
|
|
|
|
|
return ( |
|
|
|
<SearchConditionContextProvider> |
|
|
|
<Page table={table} /> |
|
|
|
<Page /> |
|
|
|
</SearchConditionContextProvider> |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
type CommonProps = { |
|
|
|
table: UseTableReturn<Contract>; |
|
|
|
}; |
|
|
|
function Page({ table }: CommonProps) { |
|
|
|
const { |
|
|
|
order, |
|
|
|
page, |
|
|
|
sort, |
|
|
|
rowsPerPage, |
|
|
|
fetched, |
|
|
|
fillteredRow, |
|
|
|
isNotFound, |
|
|
|
dataLength, |
|
|
|
// |
|
|
|
onSort, |
|
|
|
onChangePage, |
|
|
|
onChangeRowsPerPage, |
|
|
|
// |
|
|
|
setRowData, |
|
|
|
// |
|
|
|
ROWS_PER_PAGES, |
|
|
|
} = table; |
|
|
|
function Page() { |
|
|
|
const table = useTable<Contract>(); |
|
|
|
return ( |
|
|
|
<Box> |
|
|
|
<SearchBox table={table} /> |
|
|
|
@@ -68,36 +54,100 @@ function Page({ table }: CommonProps) { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
type FormProps = { |
|
|
|
id: string; |
|
|
|
name: string; |
|
|
|
}; |
|
|
|
|
|
|
|
type CommonProps = { |
|
|
|
table: UseTableReturn<Contract>; |
|
|
|
}; |
|
|
|
function SearchBox({ table }: CommonProps) { |
|
|
|
const { |
|
|
|
condition, |
|
|
|
initialized, |
|
|
|
get, |
|
|
|
addCondition: add, |
|
|
|
} = useSearchConditionContext(); |
|
|
|
|
|
|
|
const { setShowBackDrop } = useBackDrop(); |
|
|
|
const form = useForm<FormProps>({ |
|
|
|
defaultValues: { |
|
|
|
id: "", |
|
|
|
name: "", |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
const { |
|
|
|
callAPI: callGetContracts, |
|
|
|
makeSendData, |
|
|
|
sending, |
|
|
|
} = useAPICall({ |
|
|
|
apiMethod: getContracts, |
|
|
|
onSuccess: ({ data }) => { |
|
|
|
table.setRowData(data.records); |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
const handleSubmit = async (data: FormProps) => { |
|
|
|
addCondition(data); |
|
|
|
}; |
|
|
|
|
|
|
|
const addCondition = (data: FormProps) => { |
|
|
|
add({ |
|
|
|
...data, |
|
|
|
}); |
|
|
|
}; |
|
|
|
const handleBlur = () => { |
|
|
|
addCondition(form.getValues()); |
|
|
|
}; |
|
|
|
|
|
|
|
const fetch = async (data: Dictionary) => { |
|
|
|
const sendData = makeSendData({ |
|
|
|
...data, |
|
|
|
}); |
|
|
|
callGetContracts(sendData); |
|
|
|
}; |
|
|
|
|
|
|
|
// 初期値設定 |
|
|
|
useEffect(() => { |
|
|
|
if (initialized) { |
|
|
|
form.setValue("id", get("id")); |
|
|
|
form.setValue("name", get("name")); |
|
|
|
} |
|
|
|
}, [initialized, condition]); |
|
|
|
|
|
|
|
// Fetchアクション |
|
|
|
useEffect(() => { |
|
|
|
if (initialized) { |
|
|
|
fetch(condition); |
|
|
|
} |
|
|
|
}, [condition, initialized]); |
|
|
|
|
|
|
|
// バックドロップ |
|
|
|
useEffect(() => { |
|
|
|
setShowBackDrop(sending); |
|
|
|
}, [sending]); |
|
|
|
|
|
|
|
return ( |
|
|
|
<Box sx={{ p: 1, m: 1 }}> |
|
|
|
<Grid container spacing={1}> |
|
|
|
<Grid item xs={3}> |
|
|
|
<TextField label="a" fullWidth size="small" /> |
|
|
|
<FormProvider methods={form} onSubmit={form.handleSubmit(handleSubmit)}> |
|
|
|
<Box sx={{ p: 1, m: 1 }}> |
|
|
|
<Grid container spacing={2}> |
|
|
|
<Grid item xs={3} lg={2}> |
|
|
|
<Stack> |
|
|
|
<Typography>ID</Typography> |
|
|
|
<RHFTextField name="id" onBlur={handleBlur} /> |
|
|
|
</Stack> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={3} lg={2}> |
|
|
|
<Stack> |
|
|
|
<Typography>名前</Typography> |
|
|
|
<RHFTextField name="name" onBlur={handleBlur} /> |
|
|
|
</Stack> |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={3}> |
|
|
|
<TextField label="a" fullWidth size="small" /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={3}> |
|
|
|
<TextField label="a" fullWidth size="small" /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={3}> |
|
|
|
<TextField label="a" fullWidth size="small" /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={3}> |
|
|
|
<TextField label="a" fullWidth size="small" /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={3}> |
|
|
|
<TextField label="a" fullWidth size="small" /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={3}> |
|
|
|
<TextField label="a" fullWidth size="small" /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={3}> |
|
|
|
<TextField label="a" fullWidth size="small" /> |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
</FormProvider> |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -105,7 +155,6 @@ function TableBox({ table }: CommonProps) { |
|
|
|
const TABLE_HEAD = [ |
|
|
|
{ id: "id", label: "ID", align: "left" }, |
|
|
|
{ id: "name", label: "名前", align: "left" }, |
|
|
|
{ id: "emply", label: "---", align: "left" }, |
|
|
|
]; |
|
|
|
const { |
|
|
|
order, |
|
|
|
@@ -126,13 +175,6 @@ function TableBox({ table }: CommonProps) { |
|
|
|
ROWS_PER_PAGES, |
|
|
|
} = table; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
setRowData([ |
|
|
|
{ id: "iwabuchi", name: "hei" }, |
|
|
|
{ id: "iwabuchi", name: "hei1" }, |
|
|
|
]); |
|
|
|
}, []); |
|
|
|
|
|
|
|
return ( |
|
|
|
<> |
|
|
|
<TableContainer |
|
|
|
@@ -178,11 +220,18 @@ type RowProps = { |
|
|
|
data: Contract; |
|
|
|
}; |
|
|
|
function Row({ data }: RowProps) { |
|
|
|
const { navigateWhenChanged } = useNavigateCustom(); |
|
|
|
|
|
|
|
const handleClick = () => { |
|
|
|
navigateWhenChanged(getPath(PageID.DASHBOARD_CONTRACT_DETAIL), { |
|
|
|
id: data.id, |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
return ( |
|
|
|
<TableRow hover sx={{ cursor: "pointer" }}> |
|
|
|
<TableRow hover sx={{ cursor: "pointer" }} onClick={handleClick}> |
|
|
|
<TableCell>{data.id}</TableCell> |
|
|
|
<TableCell>{data.name}</TableCell> |
|
|
|
<TableCell>{data.created_at}</TableCell> |
|
|
|
</TableRow> |
|
|
|
); |
|
|
|
} |