您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

498 行
19 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 {useEffect, useState} from "react";
  8. import * as FieldUtils from "../../utils/FieldUtils";
  9. import * as HttpUtils from '../../utils/HttpUtils';
  10. import * as UrlUtils from "../../utils/ApiPathConst";
  11. import * as ComboData from "../../utils/ComboData";
  12. import { useFormik } from 'formik';
  13. import * as yup from 'yup';
  14. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  15. const UserInformationCard_Organization = ({userData, loadDataFun, orgData}) => {
  16. const [currentUserData, setCurrentUserData] = useState(userData);
  17. const [editMode, setEditMode] = useState(false);
  18. const formik = useFormik({
  19. enableReinitialize:true,
  20. initialValues:currentUserData,
  21. validationSchema:yup.object().shape({
  22. enName: yup.string().max(255).required('請輸入英文姓名'),
  23. chName: yup.string().max(255),
  24. enCompanyName: yup.string().max(255),
  25. chCompanyName: yup.string().max(255),
  26. addressLine1: yup.string().max(255).required('請輸入第一行地址'),
  27. addressLine2: yup.string().max(255),
  28. addressLine3: yup.string().max(255),
  29. emailBus: yup.string().max(255).required('請輸入電郵'),
  30. tel_countryCode: yup.string().min(3,'請輸入3位數字').required('請輸入國際區號'),
  31. fax_countryCode: yup.string().min(3,'請輸入3位數字'),
  32. phoneNumber: yup.string().min(8,'請輸入8位數字').required('請輸入聯絡電話'),
  33. faxNumber: yup.string().min(8,'請輸入8位數字'),
  34. brExpiryDate: yup.string().min(8,'請輸入商業登記證有效日期'),
  35. brNo: yup.string().min(8,'請輸入商業登記證號碼'),
  36. }),
  37. onSubmit:(values)=>{
  38. HttpUtils.post({
  39. url: UrlUtils.POST_IND_USER+"/"+userData.id,
  40. params: {
  41. chName: values.chName,
  42. enName: values.enName,
  43. contactTel: {
  44. countryCode: values.tel_countryCode,
  45. phoneNumber: values.phoneNumber
  46. },
  47. faxNo: {
  48. countryCode: values.fax_countryCode,
  49. faxNumber: values.faxNumber
  50. },
  51. addressBus: {
  52. country: values.country,
  53. district: values.district,
  54. addressLine1: values.addressLine1,
  55. addressLine2: values.addressLine2,
  56. addressLine3: values.addressLine3,
  57. },
  58. identification: values.identification,
  59. emailBus:values.emailBus,
  60. contactPerson: values.contactPerson,
  61. enCompanyName: values.enCompanyName,
  62. chCompanyName: values.chCompanyName,
  63. orgId: values.orgId,
  64. brNo: values.brNo,
  65. brExpiryDate: values.brExpiryDate,
  66. },
  67. onSuccess: function(){
  68. loadDataFun();
  69. }
  70. });
  71. }
  72. });
  73. useEffect(() => {
  74. setCurrentUserData(userData);
  75. }, [userData]);
  76. const onEditClick = () => {
  77. setEditMode(true);
  78. };
  79. const createOrgClick = () => {
  80. window.open("/org/fromUser/"+userData.id, "_blank", "noreferrer");
  81. window.addEventListener("focus", onFocus)
  82. };
  83. const onFocus=()=>{
  84. loadDataFun();
  85. window.removeEventListener("focus", onFocus)
  86. }
  87. const onVerifiedClick = () => {
  88. HttpUtils.get({
  89. url: UrlUtils.GET_IND_USER_VERIFY+"/"+userData.id,
  90. onSuccess: function(){
  91. loadDataFun();
  92. }
  93. });
  94. };
  95. const doLock = () => {
  96. HttpUtils.get({
  97. url: UrlUtils.GET_USER_LOCK+"/"+userData.id,
  98. onSuccess: function(){
  99. loadDataFun();
  100. }
  101. });
  102. };
  103. const doUnlock = () => {
  104. HttpUtils.get({
  105. url: UrlUtils.GET_USER_UNLOCK+"/"+userData.id,
  106. onSuccess: function(){
  107. loadDataFun();
  108. }
  109. });
  110. };
  111. return (
  112. <MainCard elevation={0}
  113. border={false}
  114. content={false}
  115. >
  116. <Typography variant="h5" sx={{mt: 3, ml: 3, mb: 1}}>
  117. Information
  118. </Typography>
  119. <form onSubmit={formik.handleSubmit}>
  120. {/*top button*/}
  121. <Grid item s={12} md={12} lg={12} sx={{mb: 3}} alignItems={"start"} justifyContent="center">
  122. <Grid container maxWidth justifyContent="flex-start">
  123. {editMode?
  124. <>
  125. <Grid item sx={{ml: 3, mr: 3}}>
  126. <Button
  127. size="large"
  128. variant="contained"
  129. onClick={loadDataFun}
  130. sx={{
  131. textTransform: 'capitalize',
  132. alignItems: 'end'
  133. }}
  134. >
  135. Cancel Edit
  136. </Button>
  137. </Grid>
  138. <Grid item sx={{ml: 3, mr: 3}}>
  139. <Button
  140. size="large"
  141. variant="contained"
  142. type="submit"
  143. color="success"
  144. sx={{
  145. textTransform: 'capitalize',
  146. alignItems: 'end'
  147. }}
  148. >
  149. Save
  150. </Button>
  151. </Grid>
  152. </>
  153. :
  154. <>
  155. <Grid item sx={{ml: 3, mr: 3}}>
  156. <Button
  157. size="large"
  158. variant="contained"
  159. sx={{
  160. textTransform: 'capitalize',
  161. alignItems: 'end'
  162. }}
  163. onClick={onEditClick}
  164. >
  165. Edit
  166. </Button>
  167. </Grid>
  168. </>
  169. }
  170. </Grid>
  171. </Grid>
  172. {/*end top button*/}
  173. <Grid container spacing={1}>
  174. {FieldUtils.getTextField({
  175. label:"Username:",
  176. valueName:"username",
  177. disabled:true,
  178. form: formik
  179. })}
  180. {FieldUtils.getTextField({
  181. label:"English Name:",
  182. valueName:"enName",
  183. disabled:(!editMode),
  184. form: formik
  185. })}
  186. {FieldUtils.getTextField({
  187. label:"Created Date:",
  188. valueName:"createDate",
  189. disabled:true,
  190. form: formik
  191. })}
  192. {FieldUtils.getTextField({
  193. label:"Chinese Name:",
  194. valueName:"chName",
  195. disabled:(!editMode),
  196. form: formik
  197. })}
  198. {FieldUtils.getPhoneField({
  199. label:"Contact Tel:",
  200. valueName:{
  201. code: "tel_countryCode",
  202. num:"phoneNumber"
  203. },
  204. disabled:(!editMode),
  205. form: formik
  206. })}
  207. {FieldUtils.getTextField({
  208. label:"Last Updated:",
  209. valueName:"modifieDate",
  210. disabled:true,
  211. form: formik
  212. })}
  213. {FieldUtils.getComboField({
  214. label:"Organization:",
  215. valueName:"orgId",
  216. disabled:(!editMode),
  217. dataList: orgData,
  218. filterOptions:(options) => options,
  219. getOptionLabel:(item) => item?typeof item==='number'?item+"":(item["brNo"]?item["brNo"]+"-"+item["enCompanyName"]:""):"",
  220. // getOptionSelected: (option, value) => option.label === value.label,
  221. isOptionEqualToValue:(option, newValue, setValue, setInputValue) => {
  222. if(option.id == newValue){
  223. setValue(option);
  224. setInputValue(option["brNo"]+"-"+option["enCompanyName"]);
  225. return true;
  226. }
  227. return option == newValue;
  228. },
  229. onInputChange:(event, newValue, setInputValue)=>{
  230. if(newValue != null){
  231. setInputValue(newValue);
  232. }
  233. },
  234. onChange:(event, newValue)=>{
  235. if(newValue == null){
  236. formik.setFieldValue("orgId","");
  237. return;
  238. }
  239. formik.setFieldValue("orgId",newValue.id);
  240. },
  241. form: formik
  242. })}
  243. {FieldUtils.getTextField({
  244. label:"Email:",
  245. valueName:"emailBus",
  246. disabled:(!editMode),
  247. form: formik
  248. })}
  249. <Grid item lg={4}>
  250. <Grid container alignItems={"center"}>
  251. <Grid item xs={4} s={4} md={4} lg={4}
  252. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  253. Verified:
  254. </Grid>
  255. {
  256. currentUserData.verifiedBy || editMode?
  257. <Grid item xs={6}>
  258. {FieldUtils.initField({
  259. valueName:"verifiedStatus",
  260. disabled:true,
  261. form: formik,
  262. })}
  263. </Grid>
  264. :
  265. <>
  266. <Grid item xs={4}>
  267. {FieldUtils.initField({
  268. valueName:"verifiedStatus",
  269. disabled:true,
  270. form: formik,
  271. })}
  272. </Grid>
  273. <Grid item xs={1}>
  274. <Button
  275. size="large"
  276. variant="contained"
  277. sx={{
  278. textTransform: 'capitalize',
  279. alignItems: 'end'
  280. }}
  281. onClick={onVerifiedClick}
  282. >
  283. Verify
  284. </Button>
  285. </Grid>
  286. </>
  287. }
  288. </Grid>
  289. </Grid>
  290. {FieldUtils.getTextField({
  291. label:"Last Login:",
  292. valueName:"lastLoginDate",
  293. disabled:true,
  294. form: formik
  295. })}
  296. <Grid item lg={4}>
  297. <Grid container alignItems={"center"}>
  298. <Grid item xs={4} s={4} md={4} lg={4}
  299. sx={{ml: 3, mr: 3, display: 'flex', alignItems: 'center'}}>
  300. Status:
  301. </Grid>
  302. {
  303. editMode?
  304. <Grid item xs={7} s={7} md={7} lg={6}>
  305. {FieldUtils.initField({
  306. valueName:"status",
  307. disabled:true,
  308. form: formik,
  309. })}
  310. </Grid>
  311. :
  312. <>
  313. <Grid item lg={4}>
  314. {FieldUtils.initField({
  315. valueName:"status",
  316. disabled:true,
  317. form: formik,
  318. })}
  319. </Grid>
  320. {formik.values.locked?
  321. <Grid lg={1}>
  322. <Button
  323. size="large"
  324. variant="contained"
  325. color="success"
  326. sx={{
  327. textTransform: 'capitalize',
  328. alignItems: 'end'
  329. }}
  330. onClick={doUnlock}
  331. >
  332. Active
  333. </Button>
  334. </Grid>
  335. :
  336. <Grid item lg={1}>
  337. <Button
  338. size="large"
  339. variant="contained"
  340. color="error"
  341. sx={{
  342. textTransform: 'capitalize',
  343. alignItems: 'end'
  344. }}
  345. onClick={doLock}
  346. >
  347. Lock
  348. </Button>
  349. </Grid>
  350. }
  351. </>
  352. }
  353. </Grid>
  354. </Grid>
  355. <Grid container spacing={1}>
  356. <Grid item lg={1} >
  357. <Typography variant="h5" sx={{mt: 3, ml: 3, mb: 1}}>
  358. Organization
  359. </Typography>
  360. </Grid>
  361. <Grid item lg={2}>
  362. <Button variant="contained"
  363. onClick={createOrgClick}
  364. >
  365. Create Organization
  366. </Button>
  367. </Grid>
  368. </Grid>
  369. <Grid container spacing={1}>
  370. {FieldUtils.getTextField({
  371. label:"Org.Name (English):",
  372. valueName:"enCompanyName",
  373. disabled:(!editMode),
  374. form: formik
  375. })}
  376. {FieldUtils.getTextField({
  377. label:"Org.Name (Chinese):",
  378. valueName:"chCompanyName",
  379. disabled:(!editMode),
  380. form: formik
  381. })}
  382. {FieldUtils.getTextField({
  383. label:"BR No.:",
  384. valueName:"brNo",
  385. disabled:(!editMode),
  386. form: formik
  387. })}
  388. {FieldUtils.getTextField({
  389. label:"Contact Person:",
  390. valueName:"contactPerson",
  391. disabled:(!editMode),
  392. form: formik
  393. })}
  394. {FieldUtils.getPhoneField({
  395. label:"Fax No.:",
  396. valueName:{
  397. code: "fax_countryCode",
  398. num:"faxNumber"
  399. },
  400. disabled:(!editMode),
  401. form: formik
  402. })}
  403. {FieldUtils.getDateField({
  404. label:"BR Expiry Date.:",
  405. valueName:"brExpiryDate",
  406. disabled:(!editMode),
  407. form: formik
  408. })}
  409. {FieldUtils.getAddressField({
  410. label:"Address:",
  411. valueName:["addressLine1","addressLine2","addressLine3"],
  412. disabled:(!editMode),
  413. form: formik})}
  414. {FieldUtils.getComboField({
  415. label:"District:",
  416. valueName:"district",
  417. dataList: ComboData.district,
  418. disabled:(!editMode),
  419. form: formik})}
  420. {FieldUtils.getComboField({
  421. label:"Country:",
  422. valueName:"country",
  423. dataList: ComboData.country,
  424. disabled:(!editMode),
  425. form: formik
  426. })}
  427. </Grid>
  428. </Grid>
  429. </form>
  430. </MainCard>
  431. );
  432. };
  433. export default UserInformationCard_Organization;