|
|
|
@@ -1,7 +1,11 @@ |
|
|
|
import { yupResolver } from "@hookform/resolvers/yup"; |
|
|
|
import { Box, Button, Stack, Typography } from "@mui/material"; |
|
|
|
import { Box, Button, Grid, Stack, Typography } from "@mui/material"; |
|
|
|
import { HasChildren } from "@types"; |
|
|
|
import { getHTCustomers, getHTParkings } from "api/custom/hello-techno"; |
|
|
|
import { |
|
|
|
getHTCustomers, |
|
|
|
getHTParking, |
|
|
|
getHTParkings, |
|
|
|
} from "api/custom/hello-techno"; |
|
|
|
import { |
|
|
|
FormProvider, |
|
|
|
RHFAutoComplete, |
|
|
|
@@ -12,7 +16,8 @@ import { |
|
|
|
AutoCompleteOptionType, |
|
|
|
} from "components/hook-form/RHFAutoComplete"; |
|
|
|
import useAPICall from "hooks/useAPICall"; |
|
|
|
import { useEffect, useState } from "react"; |
|
|
|
import useSnackbarCustom from "hooks/useSnackbarCustom"; |
|
|
|
import { useEffect, useMemo, useState } from "react"; |
|
|
|
import { useForm } from "react-hook-form"; |
|
|
|
import * as Yup from "yup"; |
|
|
|
|
|
|
|
@@ -32,6 +37,7 @@ type FormProps = { |
|
|
|
customerCode: AutoCompleteOptionType; |
|
|
|
parkingManagementCode: AutoCompleteOptionType; |
|
|
|
adjustSeqNo: string; |
|
|
|
serachParkingManagementCode: string; |
|
|
|
}; |
|
|
|
|
|
|
|
type Props = { |
|
|
|
@@ -41,6 +47,8 @@ export default function useSelectParkingStep({ onNext }: Props) { |
|
|
|
const [customers, setCustomers] = useState<AutoCompleteOption[]>([]); |
|
|
|
const [parkings, setParkings] = useState<AutoCompleteOption[]>([]); |
|
|
|
|
|
|
|
const { error } = useSnackbarCustom(); |
|
|
|
|
|
|
|
const customerAPI = useAPICall({ |
|
|
|
apiMethod: getHTCustomers, |
|
|
|
backDrop: true, |
|
|
|
@@ -73,11 +81,31 @@ export default function useSelectParkingStep({ onNext }: Props) { |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
const parkingByCodeAPI = useAPICall({ |
|
|
|
apiMethod: getHTParking, |
|
|
|
backDrop: true, |
|
|
|
onSuccess: ({ data }) => { |
|
|
|
const options: AutoCompleteOption[] = []; |
|
|
|
options.push({ |
|
|
|
label: data.name, |
|
|
|
value: data.parking_management_code, |
|
|
|
}); |
|
|
|
setParkings(options); |
|
|
|
|
|
|
|
form.setValue("customerCode", data.customer_code); |
|
|
|
}, |
|
|
|
onFailed: (res) => { |
|
|
|
error("駐車場の特定に失敗しました"); |
|
|
|
console.log(res); |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
const form = useForm<FormProps>({ |
|
|
|
defaultValues: { |
|
|
|
customerCode: null, |
|
|
|
parkingManagementCode: null, |
|
|
|
adjustSeqNo: "", |
|
|
|
serachParkingManagementCode: "", |
|
|
|
}, |
|
|
|
resolver: yupResolver( |
|
|
|
Yup.object().shape({ |
|
|
|
@@ -94,6 +122,7 @@ export default function useSelectParkingStep({ onNext }: Props) { |
|
|
|
}); |
|
|
|
|
|
|
|
const customerCode = form.watch("customerCode.value"); |
|
|
|
const searchParkingManagementCode = form.watch("serachParkingManagementCode"); |
|
|
|
|
|
|
|
const handleSubmit = () => { |
|
|
|
if (onNext) { |
|
|
|
@@ -101,6 +130,17 @@ export default function useSelectParkingStep({ onNext }: Props) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const handleClickSearchParking = () => { |
|
|
|
parkingByCodeAPI.callAPI({ |
|
|
|
parking_management_code: searchParkingManagementCode, |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
const canSearchParking = useMemo(() => { |
|
|
|
const reg = /^[0-9]{5}$/; |
|
|
|
return reg.test(searchParkingManagementCode); |
|
|
|
}, [searchParkingManagementCode]); |
|
|
|
|
|
|
|
// 顧客一覧取得 |
|
|
|
useEffect(() => { |
|
|
|
customerAPI.callAPI({}); |
|
|
|
@@ -108,31 +148,63 @@ export default function useSelectParkingStep({ onNext }: Props) { |
|
|
|
|
|
|
|
// 駐車場一覧取得 |
|
|
|
useEffect(() => { |
|
|
|
setParkings([]); |
|
|
|
form.setValue("parkingManagementCode", null); |
|
|
|
if (!canSearchParking) { |
|
|
|
setParkings([]); |
|
|
|
form.setValue("parkingManagementCode", null); |
|
|
|
|
|
|
|
if (customerCode) { |
|
|
|
parkingAPI.callAPI({ customer_code: customerCode }); |
|
|
|
if (customerCode) { |
|
|
|
parkingAPI.callAPI({ customer_code: customerCode }); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [customerCode]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (parkings.length === 1) { |
|
|
|
const parking = parkings[0]; |
|
|
|
form.setValue("parkingManagementCode", parking); |
|
|
|
} |
|
|
|
}, [parkings]); |
|
|
|
|
|
|
|
const element = ( |
|
|
|
<FormProvider methods={form} onSubmit={form.handleSubmit(handleSubmit)}> |
|
|
|
<Stack spacing={2} sx={{ p: 1, m: 1 }}> |
|
|
|
<AreaBox title="運営会社"> |
|
|
|
<RHFAutoComplete |
|
|
|
name="customerCode" |
|
|
|
options={customers} |
|
|
|
size="small" |
|
|
|
/> |
|
|
|
</AreaBox> |
|
|
|
<AreaBox title="駐車場"> |
|
|
|
<RHFAutoComplete |
|
|
|
name="parkingManagementCode" |
|
|
|
options={parkings} |
|
|
|
size="small" |
|
|
|
/> |
|
|
|
</AreaBox> |
|
|
|
<Grid container spacing={2}> |
|
|
|
<Grid item xs={12} md={4}> |
|
|
|
<Stack> |
|
|
|
<AreaBox title="運営会社"> |
|
|
|
<RHFAutoComplete |
|
|
|
name="customerCode" |
|
|
|
options={customers} |
|
|
|
size="small" |
|
|
|
/> |
|
|
|
</AreaBox> |
|
|
|
<AreaBox title="駐車場"> |
|
|
|
<RHFAutoComplete |
|
|
|
name="parkingManagementCode" |
|
|
|
options={parkings} |
|
|
|
size="small" |
|
|
|
/> |
|
|
|
</AreaBox> |
|
|
|
</Stack> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={12} md={4}> |
|
|
|
<Stack spacing={3}> |
|
|
|
<AreaBox title="駐車場管理コード"> |
|
|
|
<RHFTextField name="serachParkingManagementCode" /> |
|
|
|
</AreaBox> |
|
|
|
<Stack direction="row"> |
|
|
|
<Button |
|
|
|
variant="outlined" |
|
|
|
color="info" |
|
|
|
onClick={handleClickSearchParking} |
|
|
|
disabled={!canSearchParking} |
|
|
|
> |
|
|
|
検索 |
|
|
|
</Button> |
|
|
|
</Stack> |
|
|
|
</Stack> |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
<AreaBox title="精算連番"> |
|
|
|
<RHFTextField name="adjustSeqNo" size="small" /> |
|
|
|
</AreaBox> |
|
|
|
|