Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

83 righe
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. rows={4}
  42. {...register("name", {
  43. required: true,
  44. })}
  45. error={Boolean(errors.name)}
  46. helperText={
  47. Boolean(errors.name) &&
  48. (errors.name?.message
  49. ? t(errors.name.message)
  50. : t("Please input correct ") + t("name"))
  51. }
  52. />
  53. </Grid>
  54. <Grid item xs={12}>
  55. <TextField
  56. label={t("Description")}
  57. fullWidth
  58. multiline
  59. rows={4}
  60. {...register("description")}
  61. error={Boolean(errors.description)}
  62. helperText={
  63. Boolean(errors.description) &&
  64. (errors.description?.message
  65. ? t(errors.description.message)
  66. : t("Please input correct ") + t("Description"))
  67. }
  68. />
  69. </Grid>
  70. </Grid>
  71. </Box>
  72. </CardContent>
  73. </Card>
  74. );
  75. };
  76. export default GroupInfo;