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.
 
 

82 rivejä
2.4 KiB

  1. "use client";
  2. import Stack from "@mui/material/Stack";
  3. import Box from "@mui/material/Box";
  4. import Card from "@mui/material/Card";
  5. import CardContent from "@mui/material/CardContent";
  6. import Grid from "@mui/material/Grid";
  7. import TextField from "@mui/material/TextField";
  8. import Typography from "@mui/material/Typography";
  9. import { CreateGroupInputs } from "@/app/api/group/actions";
  10. import { useFormContext } from "react-hook-form";
  11. import { useTranslation } from "react-i18next";
  12. import { useCallback } from "react";
  13. const GroupInfo: React.FC = () => {
  14. const { t } = useTranslation();
  15. const {
  16. register,
  17. formState: { errors, defaultValues },
  18. control,
  19. reset,
  20. resetField,
  21. setValue,
  22. } = useFormContext<CreateGroupInputs>();
  23. const resetGroup = useCallback(() => {
  24. console.log(defaultValues);
  25. if (defaultValues !== undefined) {
  26. resetField("description");
  27. }
  28. }, [defaultValues]);
  29. return (
  30. <Card sx={{ display: "block" }}>
  31. <CardContent component={Stack} spacing={4}>
  32. <Box>
  33. <Typography variant="overline" display="block" marginBlockEnd={1}>
  34. {t("Group Info")}
  35. </Typography>
  36. <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
  37. <Grid item xs={6}>
  38. <TextField
  39. label={t("Group Name")}
  40. fullWidth
  41. {...register("name", {
  42. required: true,
  43. })}
  44. error={Boolean(errors.name)}
  45. helperText={
  46. Boolean(errors.name) &&
  47. (errors.name?.message
  48. ? t(errors.name.message)
  49. : t("Please input correct name"))
  50. }
  51. />
  52. </Grid>
  53. <Grid item xs={12}>
  54. <TextField
  55. label={t("Group Description")}
  56. fullWidth
  57. multiline
  58. rows={4}
  59. {...register("description")}
  60. error={Boolean(errors.description)}
  61. helperText={
  62. Boolean(errors.description) &&
  63. (errors.description?.message
  64. ? t(errors.description.message)
  65. : t("Please input correct description"))
  66. }
  67. />
  68. </Grid>
  69. </Grid>
  70. </Box>
  71. </CardContent>
  72. </Card>
  73. );
  74. };
  75. export default GroupInfo;