Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

192 lignes
7.5 KiB

  1. // material-ui
  2. import {
  3. Grid, Typography, Button
  4. } from '@mui/material';
  5. import MainCard from "../../components/MainCard";
  6. import * as React from "react";
  7. import * as yup from 'yup';
  8. import {useEffect, useState} from "react";
  9. import * as HttpUtils from '../../utils/HttpUtils';
  10. import * as UrlUtils from "../../utils/ApiPathConst";
  11. import * as FieldUtils from "../../utils/FieldUtils";
  12. import * as ComboData from "../../utils/ComboData";
  13. import {useNavigate} from "react-router-dom";
  14. import { useFormik } from 'formik';
  15. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  16. const OrganizationCard_loadFromUser = ({userData,userId}) => {
  17. const [currentUserData, setCurrentUserData] = useState(userData);
  18. const navigate = useNavigate();
  19. const formik = useFormik({
  20. enableReinitialize:true,
  21. initialValues:currentUserData,
  22. validationSchema:yup.object().shape({
  23. enCompanyName: yup.string().max(255,"請輸入英文名稱").required('請輸入英文名稱'),
  24. chCompanyName: yup.string().max(255,'請輸入中文名稱').nullable(),
  25. addressLine1: yup.string().max(255).required('請輸入第一行地址'),
  26. addressLine2: yup.string().max(255).nullable(),
  27. addressLine3: yup.string().max(255).nullable(),
  28. fax_countryCode: yup.string().min(3,"請輸入國際區號").nullable(),
  29. tel_countryCode: yup.string().min(3,"請輸入國際區號"),
  30. phoneNumber: yup.string().min(8, '請輸入有效聯絡電話').required('請輸入聯絡電話'),
  31. faxNumber: yup.string().min(8).nullable(),
  32. brExpiryDate: yup.string().min(8).required('請輸入商業登記證有效日期'),
  33. brNo: yup.string().min(8, '請輸入有效商業登記證號碼').max(8,'請輸入有效商業登記證號碼').required('請輸入商業登記證號碼'),
  34. }),
  35. onSubmit: values =>{
  36. HttpUtils.post({
  37. url: UrlUtils.POST_ORG_SAVE_PATH,
  38. params: {
  39. id:null,
  40. primaryUserId:userId,
  41. enCompanyName: values.enCompanyName,
  42. chCompanyName: values.chCompanyName,
  43. brNo: values.brNo,
  44. brExpiryDate: values.brExpiryDate,
  45. enCompanyNameTemp: values.enCompanyNameTemp,
  46. chCompanyNameTemp: values.chCompanyNameTemp,
  47. brExpiryDateTemp: values.brExpiryDateTemp,
  48. contactPerson: values.contactPerson,
  49. contactTel: {
  50. countryCode: values.tel_countryCode,
  51. phoneNumber: values.phoneNumber
  52. },
  53. faxNo: {
  54. countryCode: values.fax_countryCode,
  55. faxNumber: values.faxNumber
  56. },
  57. addressTemp: {
  58. country: values.country,
  59. district: values.district,
  60. addressLine1: values.addressLine1,
  61. addressLine2: values.addressLine2,
  62. addressLine3: values.addressLine3,
  63. }
  64. },
  65. onSuccess: function(responseData){
  66. navigate('/org/'+responseData.id);
  67. }
  68. });
  69. }
  70. });
  71. useEffect(() => {
  72. setCurrentUserData(userData);
  73. }, [userData]);
  74. return (
  75. <MainCard elevation={0}
  76. border={false}
  77. content={false}
  78. >
  79. <Typography variant="h5" sx={{mt: 3, ml: 3, mb: 1}}>
  80. Information
  81. </Typography>
  82. {/* <div style={{ border: "solid 1px;", color: "red" }}>
  83. TODO: Error Summary
  84. {Object.values(formik.errors).map(error => (
  85. <div>{error}</div>
  86. ))}
  87. </div> */}
  88. <form onSubmit={formik.handleSubmit}>
  89. <Grid container spacing={1}>
  90. {/*top*/}
  91. <Grid item s={12} md={12} lg={12} sx={{mb: 3}} alignItems={"start"} justifyContent="center">
  92. <Grid item sx={{ml: 3, mr: 3}}>
  93. <Button
  94. size="large"
  95. variant="contained"
  96. type="submit"
  97. sx={{
  98. textTransform: 'capitalize',
  99. alignItems: 'end'
  100. }}
  101. >
  102. Create
  103. </Button>
  104. </Grid>
  105. </Grid>
  106. {/*top*/}
  107. {FieldUtils.getTextField({
  108. label:"BR No.:",
  109. valueName:"brNo",
  110. form: formik})}
  111. <Grid item lg={8}></Grid>
  112. {FieldUtils.getTextField({
  113. label:FieldUtils.notNullFieldLabel("Name (Eng):"),
  114. valueName:"enCompanyName",
  115. form: formik})}
  116. {FieldUtils.getTextField({
  117. label:"Name (Ch):",
  118. valueName:"chCompanyName",
  119. form: formik})}
  120. {FieldUtils.getDateField({
  121. label:FieldUtils.notNullFieldLabel("Expiry Date:"),
  122. valueName:"brExpiryDate",
  123. form: formik})}
  124. {FieldUtils.getTextField({
  125. label:FieldUtils.notNullFieldLabel("Contact Person:"),
  126. valueName:"contactPerson",
  127. form: formik})}
  128. {FieldUtils.getPhoneField({
  129. label:FieldUtils.notNullFieldLabel("Contact Tel:"),
  130. valueName:{
  131. code:"tel_countryCode",
  132. num:"phoneNumber"
  133. },
  134. form: formik})}
  135. {FieldUtils.getPhoneField({
  136. label:"Fax No:",
  137. valueName:{
  138. code:"fax_countryCode",
  139. num:"faxNumber"
  140. },
  141. form: formik})}
  142. {FieldUtils.getComboField({
  143. label:FieldUtils.notNullFieldLabel("Country:"),
  144. valueName:"country",
  145. dataList: ComboData.country,
  146. form: formik})}
  147. {FieldUtils.getComboField({
  148. label:FieldUtils.notNullFieldLabel("District:"),
  149. valueName:"district",
  150. dataList: ComboData.district,
  151. form: formik})}
  152. {FieldUtils.getAddressField({
  153. label:FieldUtils.notNullFieldLabel("Address:"),
  154. valueName:["addressLine1","addressLine2","addressLine3"],
  155. form: formik})}
  156. </Grid>
  157. </form>
  158. </MainCard>
  159. );
  160. };
  161. export default OrganizationCard_loadFromUser;