"use client"; import React from "react"; import { Box, TextField, IconButton, Button, Typography, } from "@mui/material"; import DeleteOutlineOutlinedIcon from "@mui/icons-material/DeleteOutlineOutlined"; import AddIcon from "@mui/icons-material/Add"; import { FieldArray, Form, getIn, type FormikProps } from "formik"; import { COURSE_EMPTY_ITEM, CourseFormProps, CourseFormValues, CourseItem } from "./CourseForm"; type Props = FormikProps & CourseFormProps; export default function InnerCourseForm(props: Props) { const { values, errors, touched, handleChange, setFieldValue } = props; const handleBack = () => { props.update({ courses: props.values.courses }); props.setStep(props.step - 1); }; return (
{({ push, remove }) => ( <> {values.courses.map((course: CourseItem, index: number) => { const itemErrors = getIn(errors, `courses.${index}`) || {}; const itemTouched = getIn(touched, `courses.${index}`) || {}; return ( {values.courses.length > 1 && ( remove(index)} color="error" sx={{ position: "absolute", top: 8, right: 8, zIndex: 2 }} aria-label="remove-course" > )} دوره {index + 1} setFieldValue( `courses.${index}.year`, e.target.value === "" ? "" : Number(e.target.value), ) } error={!!itemTouched.year && !!itemErrors.year} helperText={itemTouched.year ? itemErrors.year : ""} /> ); })} )}
); }