FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

126 lines
6.2 KiB

  1. "use client"
  2. import { M18ImportTestingForm, M18ImportPqForm } from "@/app/api/settings/m18ImportTesting/actions";
  3. import { INPUT_DATE_FORMAT, OUTPUT_DATE_FORMAT, OUTPUT_TIME_FORMAT, dateTimeStringToDayjs } from "@/app/utils/formatUtil";
  4. import { Check } from "@mui/icons-material";
  5. import { Box, Button, Card, CardContent, FormControl, Grid, Stack, Typography } from "@mui/material";
  6. import { DatePicker, DateTimePicker, LocalizationProvider } from "@mui/x-date-pickers";
  7. import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
  8. import dayjs, { Dayjs } from "dayjs";
  9. import React, { useCallback, useState } from "react";
  10. import { Controller, useFormContext } from "react-hook-form";
  11. import { useTranslation } from "react-i18next";
  12. interface Props {
  13. }
  14. const M18ImportPq: React.FC<Props> = ({
  15. }) => {
  16. const { t } = useTranslation()
  17. const [isLoading, setIsLoading] = useState(false)
  18. const {
  19. control,
  20. formState: { errors },
  21. watch
  22. } = useFormContext<M18ImportTestingForm>()
  23. const handleDateTimePickerOnChange = useCallback((value: Dayjs | null, onChange: (value: any) => void) => {
  24. const formattedValue = value ? value.format(`${INPUT_DATE_FORMAT} ${OUTPUT_TIME_FORMAT}`) : null
  25. onChange(formattedValue)
  26. }, [])
  27. return (
  28. <Card sx={{ width: '100%' }}>
  29. <CardContent sx={{ display: "flex", flexDirection: "column", gap: 1 }}>
  30. <Grid container>
  31. <Grid container>
  32. <Typography variant="overline">{t("Import Purchase Quotation")}</Typography>
  33. </Grid>
  34. <Grid item xs={8}>
  35. <LocalizationProvider
  36. dateAdapter={AdapterDayjs}
  37. // TODO: Should maybe use a custom adapterLocale here to support YYYY-MM-DD
  38. adapterLocale="zh-hk"
  39. >
  40. <Box display="flex">
  41. <Controller
  42. control={control}
  43. name="pq.modifiedDateFrom"
  44. // rules={{
  45. // // required: "Please input the date From!",
  46. // validate: {
  47. // isValid: (value) =>
  48. // value && dateTimeStringToDayjs(value).isValid() ? true : "Invalid date-time"
  49. // },
  50. // }}
  51. render={({ field, fieldState: { error } }) => (
  52. <DateTimePicker
  53. label={t("Modified Date From")}
  54. format={`${OUTPUT_DATE_FORMAT} ${OUTPUT_TIME_FORMAT}`}
  55. onChange={(newValue: Dayjs | null) => (handleDateTimePickerOnChange(newValue, field.onChange))}
  56. slotProps={{
  57. textField: {
  58. error: !!error,
  59. helperText: error ? error.message : null
  60. }
  61. }}
  62. />
  63. )}
  64. />
  65. <Box
  66. display="flex"
  67. alignItems="center"
  68. justifyContent="center"
  69. marginInline={2}
  70. >
  71. {"-"}
  72. </Box>
  73. <Controller
  74. control={control}
  75. name="pq.modifiedDateTo"
  76. // rules={{
  77. // // required: "Please input the date to!",
  78. // validate: {
  79. // isValid: (value) =>
  80. // value && dateTimeStringToDayjs(value).isValid() ? true : "Invalid date-time",
  81. // isFuture: (value) =>
  82. // dateTimeStringToDayjs(value).isAfter(watch("po.dateFrom")) || "Date must be in the future",
  83. // },
  84. // }}
  85. render={({ field, fieldState: { error } }) => (
  86. <DateTimePicker
  87. label={t("Modified Date To")}
  88. format={`${OUTPUT_DATE_FORMAT} ${OUTPUT_TIME_FORMAT}`}
  89. onChange={(newValue: Dayjs | null) => (handleDateTimePickerOnChange(newValue, field.onChange))}
  90. slotProps={{
  91. textField: {
  92. error: !!error,
  93. helperText: error ? error.message : null
  94. }
  95. }}
  96. />
  97. )}
  98. />
  99. </Box>
  100. </LocalizationProvider>
  101. </Grid>
  102. </Grid>
  103. <Stack direction="row" justifyContent="flex-end" gap={1}>
  104. <Button
  105. name="m18ImportPq"
  106. id="m18ImportPq"
  107. variant="contained"
  108. startIcon={<Check />}
  109. type="submit"
  110. >
  111. {t("Import Pq")}
  112. </Button>
  113. </Stack>
  114. </CardContent>
  115. </Card>
  116. )
  117. }
  118. export default M18ImportPq;