// material-ui import { Grid, Typography, Button, RadioGroup, Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material'; import { useFormik } from 'formik'; import * as yup from 'yup'; import * as React from "react"; import * as HttpUtils from "utils/HttpUtils"; import * as UrlUtils from "utils/ApiPathConst"; import * as FieldUtils from "utils/FieldUtils"; import {useNavigate} from "react-router-dom"; // ==============================|| DASHBOARD - DEFAULT ||============================== // const PublicNoticeApplyForm = ({loadedData, selections}) => { const [isWarningPopUp, setIsWarningPopUp] = React.useState(false); const [warningText, setWarningText] = React.useState(""); const [attachment, setAttachment] = React.useState({}); const navigate=useNavigate(); // React.useEffect(()=>{ // setFormData(loadedData); // },[]); const formik = useFormik({ enableReinitialize:true, initialValues:loadedData, validationSchema:yup.object().shape({ contactPerson: yup.string().max(40).required('請輸入聯絡人'), tel_countryCode: yup.string().min(3,'請輸入3位數字').required('請輸入國際區號'), fax_countryCode: yup.string().min(3,'請輸入3位數字'), phoneNumber: yup.string().min(8,'請輸入8位數字').required('請輸入聯絡電話'), faxNumber: yup.string().min(8,'請輸入8位數字'), remarks: yup.string().max(255).nullable(), }), onSubmit:values=>{ if(!values.issueId){ setWarningText("請選擇目標期數"); setIsWarningPopUp(true); return; } if(!attachment){ setWarningText("請選擇上傳文件"); setIsWarningPopUp(true); return; }else if(attachment.size >= (10*1024*1034)){ setWarningText("上傳文件大小應<10MB"); setIsWarningPopUp(true); return; } console.log(values); HttpUtils.postWithFiles({ url: UrlUtils.POST_PUBLIC_NOTICE_APPLY, params: { id: 0, contactPerson: values.contactPerson, contactTelNo: { countryCode: values.tel_countryCode, phoneNumber: values.phoneNumber }, contactFaxNo:{ countryCode: values.fax_countryCode, faxNumber: values.faxNumber }, issueId:values.issueId, remarks:values.remarks, }, files: [attachment], onSuccess: function(){ navigate("/publicNotice"); } }); } }); const readFile=(event)=>{ setAttachment(event.target.files[0]); } return ( 申請公共啟事
{FieldUtils.getTextField({ label:"聯絡人:", valueName:"contactPerson", form: formik })} {FieldUtils.getPhoneField({ label:"聯繫電話:", valueName:{ code: "tel_countryCode", num:"phoneNumber" }, form: formik })} {FieldUtils.getPhoneField({ label:"聯繫傳真:", valueName:{ code: "fax_countryCode", num:"faxNumber" }, form: formik })} 目標期數: { selections } 上傳文件 ({"檔案大小應<10MB"}): {attachment.name} { readFile(event) }} /> {FieldUtils.getTextArea({ label:"備註:", valueName:"remarks", form: formik })}
setIsWarningPopUp(false)} > Warning {warningText}
); }; export default PublicNoticeApplyForm;