import { forwardRef , ReactElement , Ref } from "react" import Dialog from '@mui/material/Dialog'; import DialogTitle from '@mui/material/DialogTitle'; import { useDispatch } from "react-redux"; import { AppDispatch, useAppSelector } from "@/redux/store"; import { setAddPopUp , add } from "@/redux/features/services-slice" import { useTranslations } from "next-intl"; import { useTheme } from '@mui/material/styles'; import useMediaQuery from '@mui/material/useMediaQuery'; import Slide from '@mui/material/Slide'; import { TransitionProps } from '@mui/material/transitions'; import { Formik } from 'formik'; import DialogContent from '@mui/material/DialogContent'; import DialogContentText from '@mui/material/DialogContentText'; import DialogActions from '@mui/material/DialogActions'; import CircularProgress from '@mui/material/CircularProgress'; import * as Yup from "yup"; export default function AddPopUp() { // declare the needed variables // redux const dispatch = useDispatch(); // intl-18 const t = useTranslations('services'); // mui const theme = useTheme(); const fullScreen = useMediaQuery(theme.breakpoints.down('md')); // get state from redux const addPopUp = useAppSelector((state) => state.servicesReducer.value.addPopUp) // setup the popup animation const Transition = forwardRef(function Transition( props: TransitionProps & { children: ReactElement; }, ref: Ref, ) { return ; }); // setup the function that close the popup const handleClose = () => { dispatch(setAddPopUp(false)); }; // we dont mount the pop up if we dont need it if(!addPopUp) return <> // we mount the popup if we needed it return ( { // This is the title of the pop up }

{t('addNewService')}

handleClose()} className="fill-primary-dark dark:fill-primary cursor-pointer">
{ // Formik form start from here } { await dispatch(add(values)) handleClose(); }} > {({ handleChange, handleBlur, handleSubmit, isSubmitting, values, setFieldValue, errors, touched }) => ( <>
{ // dialog content contain the formik form } { // dialog text content contain a small description to the current form part }

{t('serviceAddText1')}

{t('serviceInformations')}

{errors?.name && touched?.name && t(errors?.name)}