選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UserInformationCard_Organization.js 28 KiB

2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. // material-ui
  2. import {
  3. Grid, Typography, Button,
  4. Dialog, DialogTitle, DialogContent, DialogActions
  5. } from '@mui/material';
  6. import MainCard from "../../../components/MainCard";
  7. import * as React 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. const LoadingComponent = Loadable(lazy(() => import('../../extra-pages/LoadingComponent')));
  15. import Loadable from 'components/Loadable';
  16. import { lazy } from 'react';
  17. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  18. const UserInformationCard_Organization = ({ userData, loadDataFun, orgData }) => {
  19. const [currentUserData, setCurrentUserData] = React.useState(userData);
  20. const [isWarningPopUp, setIsWarningPopUp] = React.useState(false);
  21. const [warningText, setWarningText] = React.useState("");
  22. const [isConfirmPopUp, setIsConfirmPopUp] = React.useState(false);
  23. const [confirmText, setConfirmText] = React.useState("");
  24. const [confirmAction, setConfirmAction] = React.useState();
  25. const [editMode, setEditMode] = React.useState(false);
  26. const [onReady, setOnReady] = React.useState(false);
  27. React.useEffect(() => {
  28. //if state data are ready and assign to different field
  29. // console.log(currentApplicationDetailData)
  30. if (Object.keys(currentUserData).length > 0) {
  31. setOnReady(true);
  32. }
  33. }, [currentUserData]);
  34. const formik = useFormik({
  35. enableReinitialize: true,
  36. initialValues: currentUserData,
  37. validationSchema: yup.object().shape({
  38. contactPerson: yup.string().max(255).required('請輸入姓名'),
  39. enCompanyName: yup.string().max(255).required('請輸入英文名稱'),
  40. chCompanyName: yup.string().max(255).nullable(),
  41. addressLine1: yup.string().max(255).required('請輸入第一行地址'),
  42. addressLine2: yup.string().max(255).nullable(),
  43. addressLine3: yup.string().max(255).nullable(),
  44. emailBus: yup.string().max(255).required('請輸入電郵'),
  45. tel_countryCode: yup.string().min(3, '請輸入3位數字').required('請輸入國際區號'),
  46. fax_countryCode: yup.string().min(3, '請輸入3位數字').nullable(),
  47. phoneNumber: yup.string().min(8, '請輸入8位數字').required('請輸入聯絡電話'),
  48. faxNumber: yup.string().min(8, '請輸入8位數字').nullable(),
  49. brExpiryDate: yup.string().min(8, '請輸入商業登記證有效日期'),
  50. brNo: yup.string().min(8, '請輸入有效商業登記證號碼').max(8, '請輸入有效商業登記證號碼').required('請輸入商業登記證號碼'),
  51. }),
  52. onSubmit: (values) => {
  53. HttpUtils.post({
  54. url: UrlUtils.POST_ORG_USER + "/" + userData.id,
  55. params: {
  56. contactTel: {
  57. countryCode: values.tel_countryCode,
  58. phoneNumber: values.phoneNumber
  59. },
  60. // faxNo: {
  61. // countryCode: values.fax_countryCode,
  62. // faxNumber: values.faxNumber
  63. // },
  64. // addressBus: {
  65. // country: values.country,
  66. // district: values.district,
  67. // addressLine1: values.addressLine1,
  68. // addressLine2: values.addressLine2,
  69. // addressLine3: values.addressLine3,
  70. // },
  71. identification: values.identification,
  72. emailBus: values.emailBus,
  73. contactPerson: values.contactPerson,
  74. // enCompanyName: values.enCompanyName,
  75. // chCompanyName: values.chCompanyName,
  76. orgId: values.orgId,
  77. // brNo: values.brNo,
  78. // brExpiryDate: values.brExpiryDate,
  79. },
  80. onSuccess: function () {
  81. loadDataFun();
  82. }
  83. });
  84. }
  85. });
  86. React.useEffect(() => {
  87. if (Object.keys(userData).length > 0) {
  88. setCurrentUserData(userData);
  89. }
  90. }, [userData]);
  91. const onEditClick = () => {
  92. setEditMode(true);
  93. };
  94. const createOrgClick = () => {
  95. window.open("/org/fromUser/" + userData.id, "_blank", "noreferrer");
  96. window.addEventListener("focus", onFocus)
  97. };
  98. const onFocus = () => {
  99. loadDataFun();
  100. window.removeEventListener("focus", onFocus)
  101. }
  102. const onVerifiedClick = () => {
  103. if (formik?.values?.orgId) {
  104. HttpUtils.get({
  105. url: UrlUtils.GET_IND_USER_VERIFY + "/" + userData.id,
  106. onSuccess: function () {
  107. loadDataFun();
  108. }
  109. });
  110. } else {
  111. setWarningText("Please select Organization before active this account.")
  112. setIsWarningPopUp(true);
  113. }
  114. };
  115. const doLock = () => {
  116. setConfirmText("Confirm to Lock this Account?");
  117. setConfirmAction({
  118. function: function () {
  119. HttpUtils.get({
  120. url: UrlUtils.GET_USER_LOCK + "/" + userData.id,
  121. onSuccess: function () {
  122. loadDataFun();
  123. }
  124. });
  125. }
  126. });
  127. setIsConfirmPopUp(true);
  128. };
  129. const doUnlock = () => {
  130. setConfirmText("Confirm to Un-Lock this Account?");
  131. setConfirmAction({
  132. function: function () {
  133. HttpUtils.get({
  134. url: UrlUtils.GET_USER_UNLOCK + "/" + userData.id,
  135. onSuccess: function () {
  136. loadDataFun();
  137. }
  138. });
  139. }
  140. });
  141. setIsConfirmPopUp(true);
  142. };
  143. return (
  144. <MainCard elevation={0}
  145. border={false}
  146. content={false}
  147. >
  148. {!onReady?
  149. <LoadingComponent />
  150. :
  151. <form onSubmit={formik.handleSubmit}>
  152. {/*top button*/}
  153. <Grid item s={12} md={12} lg={12} sx={{ mb: 3 }} alignItems={"start"} justifyContent="center">
  154. <Grid container maxWidth justifyContent="flex-start">
  155. {editMode ?
  156. <>
  157. <Grid item sx={{ ml: 3, mr: 3 }}>
  158. <Button
  159. size="large"
  160. variant="contained"
  161. onClick={loadDataFun}
  162. sx={{
  163. textTransform: 'capitalize',
  164. alignItems: 'end'
  165. }}
  166. >
  167. Reset & Back
  168. </Button>
  169. </Grid>
  170. <Grid item sx={{ ml: 3, mr: 3 }}>
  171. <Button
  172. size="large"
  173. variant="contained"
  174. type="submit"
  175. color="success"
  176. sx={{
  177. textTransform: 'capitalize',
  178. alignItems: 'end'
  179. }}
  180. >
  181. Save
  182. </Button>
  183. </Grid>
  184. </>
  185. :
  186. <>
  187. <Grid item sx={{ ml: 3, mr: 3 }}>
  188. <Button
  189. size="large"
  190. variant="contained"
  191. sx={{
  192. textTransform: 'capitalize',
  193. alignItems: 'end'
  194. }}
  195. onClick={onEditClick}
  196. >
  197. Edit
  198. </Button>
  199. </Grid>
  200. </>
  201. }
  202. </Grid>
  203. </Grid>
  204. {/*end top button*/}
  205. <div style={{ paddingLeft: 24, paddingRight: 24 }}>
  206. <Grid container spacing={1}>
  207. <Grid item lg={4}>
  208. {FieldUtils.getTextField({
  209. label: "Username:",
  210. valueName: "username",
  211. disabled: true,
  212. form: formik
  213. })}
  214. </Grid>
  215. <Grid item lg={4}>
  216. {FieldUtils.getTextField({
  217. label: "Name:",
  218. valueName: "contactPerson",
  219. disabled: (!editMode),
  220. form: formik
  221. })}
  222. </Grid>
  223. <Grid item lg={4}>
  224. {FieldUtils.getTextField({
  225. label: "Created Date:",
  226. valueName: "createDate",
  227. disabled: true,
  228. form: formik
  229. })}
  230. </Grid>
  231. <Grid item lg={4}>
  232. {FieldUtils.getTextField({
  233. label: "Email:",
  234. valueName: "emailBus",
  235. disabled: (!editMode),
  236. form: formik
  237. })}
  238. </Grid>
  239. <Grid item lg={4}>
  240. {FieldUtils.getPhoneField({
  241. label: "Contact Tel:",
  242. valueName: {
  243. code: "tel_countryCode",
  244. num: "phoneNumber"
  245. },
  246. disabled: (!editMode),
  247. form: formik
  248. })}
  249. </Grid>
  250. <Grid item lg={4}>
  251. {FieldUtils.getTextField({
  252. label: "Last Updated:",
  253. valueName: "modifieDate",
  254. disabled: true,
  255. form: formik
  256. })}
  257. </Grid>
  258. <Grid item lg={4}>
  259. {FieldUtils.getComboField({
  260. label: "Organization:",
  261. valueName: "orgId",
  262. disabled: (!editMode),
  263. dataList: orgData,
  264. filterOptions: (options, state) => {
  265. if (!state || !state.inputValue) return options;
  266. let searchStr = state.inputValue.toLowerCase().toLowerCase().trim();
  267. const displayOptions = options.filter((option) => {
  268. let brNo = option.brNo.toLowerCase().trim();
  269. let enCompanyName = option.enCompanyName ? option.enCompanyName.toLowerCase().trim() : "";
  270. let chCompanyName = option.chCompanyName ? option.chCompanyName.toLowerCase().trim() : "";
  271. return brNo.includes(searchStr) || enCompanyName.includes(searchStr) || chCompanyName.includes(searchStr);
  272. },
  273. );
  274. return displayOptions;
  275. },
  276. getOptionLabel: (item) => item ? typeof item === 'number' ? item + "" : (item["brNo"] ?
  277. <div>BR No.: {item["brNo"]}<div>Org. Name(Eng): {item["enCompanyName"] === null ? "N/A" : item["enCompanyName"]}</div><div>Org. Name(CH): {item["chCompanyName"] === null ? "N/A" : item["chCompanyName"]}</div></div>: "")
  278. : "",
  279. isOptionEqualToValue: (option, newValue, setValue, setInputValue) => {
  280. if (option.id == newValue || option.id == newValue.id) {
  281. setValue(option);
  282. setInputValue(option["brNo"]);
  283. return true;
  284. }
  285. return option == newValue || option.id == newValue.id;
  286. },
  287. onInputChange: (event, newValue, setInputValue) => {
  288. if (newValue !== "[object Object]" ) {
  289. setInputValue(newValue);
  290. }
  291. },
  292. onChange: (event, newValue) => {
  293. if (newValue == null) {
  294. formik.setFieldValue("orgId", "");
  295. return;
  296. }
  297. formik.setFieldValue("orgId", newValue.id);
  298. },
  299. form: formik
  300. })}
  301. </Grid>
  302. <Grid item lg={4}>
  303. <Grid container alignItems={"center"}>
  304. <Grid item xs={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  305. Verified:
  306. </Grid>
  307. {
  308. currentUserData.verifiedBy || editMode ?
  309. <Grid item xs={12} md={6} lg={6}>
  310. {FieldUtils.initField({
  311. valueName: "verifiedStatus",
  312. disabled: true,
  313. form: formik,
  314. })}
  315. </Grid>
  316. :
  317. <>
  318. <Grid item xs={10} md={4} lg={4}>
  319. {FieldUtils.initField({
  320. valueName: "verifiedStatus",
  321. disabled: true,
  322. form: formik,
  323. })}
  324. </Grid>
  325. <Grid item xs={1} md={1} lg={1}>
  326. <Button
  327. size="large"
  328. variant="contained"
  329. sx={{
  330. textTransform: 'capitalize',
  331. alignItems: 'end'
  332. }}
  333. onClick={() => { onVerifiedClick() }}
  334. >
  335. Verify
  336. </Button>
  337. </Grid>
  338. </>
  339. }
  340. </Grid>
  341. </Grid>
  342. <Grid item lg={4}>
  343. {FieldUtils.getTextField({
  344. label: "Last Login:",
  345. valueName: "lastLoginDate",
  346. disabled: true,
  347. form: formik
  348. })}
  349. </Grid>
  350. <Grid item lg={8}></Grid>
  351. <Grid item lg={4}>
  352. <Grid container alignItems={"center"}>
  353. <Grid item xs={12} md={3} lg={3} sx={{ display: 'flex', alignItems: 'center' }}>
  354. Status:
  355. </Grid>
  356. {
  357. editMode ?
  358. <Grid item xs={12} md={6} lg={6}>
  359. {FieldUtils.initField({
  360. valueName: "status",
  361. disabled: true,
  362. form: formik,
  363. })}
  364. </Grid>
  365. :
  366. <>
  367. <Grid item xs={10} md={4} lg={4}>
  368. {FieldUtils.initField({
  369. valueName: "status",
  370. disabled: true,
  371. form: formik,
  372. })}
  373. </Grid>
  374. {formik.values.locked ?
  375. <Grid item xs={1} md={1} lg={1}>
  376. <Button
  377. size="large"
  378. variant="contained"
  379. color="success"
  380. sx={{
  381. textTransform: 'capitalize',
  382. alignItems: 'end'
  383. }}
  384. onClick={doUnlock}
  385. >
  386. Active
  387. </Button>
  388. </Grid>
  389. :
  390. <Grid item xs={1} md={1} lg={1}>
  391. <Button
  392. size="large"
  393. variant="contained"
  394. color="error"
  395. sx={{
  396. textTransform: 'capitalize',
  397. alignItems: 'end'
  398. }}
  399. onClick={doLock}
  400. >
  401. Lock
  402. </Button>
  403. </Grid>
  404. }
  405. </>
  406. }
  407. </Grid>
  408. </Grid>
  409. </Grid>
  410. </div>
  411. <div style={{ paddingLeft: 24, paddingRight: 24 }}>
  412. <Grid container spacing={1} >
  413. <Grid item lg={12} >
  414. <Grid container alignItems={"center"}>
  415. <Grid item lg={1} >
  416. <Typography variant="h5" sx={{ display: 'flex', alignItems: 'center' }}>
  417. Organization
  418. </Typography>
  419. </Grid>
  420. {currentUserData.orgId==null?
  421. <Grid item lg={2} >
  422. <Button variant="contained"
  423. onClick={createOrgClick}
  424. >
  425. Create Organization
  426. </Button>
  427. </Grid>
  428. :null
  429. }
  430. </Grid>
  431. </Grid>
  432. <Grid item lg={4}>
  433. {FieldUtils.getTextField({
  434. label: "Org.Name (English):",
  435. valueName: "enCompanyName",
  436. disabled: true,
  437. form: formik
  438. })}
  439. </Grid>
  440. <Grid item lg={4}>
  441. {FieldUtils.getTextField({
  442. label: "Org.Name (Chinese):",
  443. valueName: "chCompanyName",
  444. disabled: true,
  445. form: formik
  446. })}
  447. </Grid>
  448. <Grid item lg={4}>
  449. {FieldUtils.getTextField({
  450. label: "BR No.:",
  451. valueName: "brNo",
  452. disabled: true,
  453. form: formik
  454. })}
  455. </Grid>
  456. <Grid item lg={4}>
  457. {FieldUtils.getComboField({
  458. label: "Country:",
  459. valueName: "country",
  460. dataList: ComboData.country,
  461. disabled: true,
  462. form: formik
  463. })}
  464. </Grid>
  465. <Grid item lg={4}>
  466. {FieldUtils.getPhoneField({
  467. label: "Fax No.:",
  468. valueName: {
  469. code: "fax_countryCode",
  470. num: "faxNumber"
  471. },
  472. disabled: true,
  473. form: formik
  474. })}
  475. </Grid>
  476. <Grid item lg={4}>
  477. {FieldUtils.getDateField({
  478. label: "BR Expiry Date.:",
  479. valueName: "brExpiryDate",
  480. disabled: true,
  481. form: formik
  482. })}
  483. </Grid>
  484. <Grid item lg={4}>
  485. {FieldUtils.getAddressField({
  486. label: "Address:",
  487. valueName: ["addressLine1", "addressLine2", "addressLine3"],
  488. disabled: true,
  489. form: formik
  490. })}
  491. </Grid>
  492. <Grid item lg={4}>
  493. {FieldUtils.getComboField({
  494. label: "District:",
  495. valueName: "district",
  496. dataList: ComboData.district,
  497. disabled: true,
  498. form: formik
  499. })}
  500. </Grid>
  501. </Grid>
  502. </div>
  503. </form>
  504. }
  505. <div>
  506. <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} >
  507. <DialogTitle>Warning</DialogTitle>
  508. <DialogContent style={{ display: 'flex', }}>
  509. <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography>
  510. </DialogContent>
  511. <DialogActions>
  512. <Button onClick={() => setIsWarningPopUp(false)}>Close</Button>
  513. </DialogActions>
  514. </Dialog>
  515. </div>
  516. <div>
  517. <Dialog open={isConfirmPopUp} onClose={() => setIsConfirmPopUp(false)} >
  518. <DialogTitle>Confirm</DialogTitle>
  519. <DialogContent style={{ display: 'flex', }}>
  520. <Typography variant="h3" style={{ padding: '16px' }}>{confirmText}</Typography>
  521. </DialogContent>
  522. <DialogActions>
  523. <Button onClick={() => { setIsConfirmPopUp(false) }}>Close</Button>
  524. <Button onClick={() => { confirmAction?.function(); }}>Confirm</Button>
  525. </DialogActions>
  526. </Dialog>
  527. </div>
  528. </MainCard>
  529. );
  530. };
  531. export default UserInformationCard_Organization;