@undp/carbon-library 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  import "./addNewCompanyComponent.scss";
3
3
  import "../../../Styles/app.scss";
4
4
  export declare const AddNewCompanyComponent: (props: any) => React.JSX.Element;
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PlusOutlined, FilterOutlined, BankOutlined, SafetyOutlined, ExperimentOutlined, UploadOutlined, EllipsisOutlined, StarOutlined, SearchOutlined, ToolOutlined, EyeOutlined, EditOutlined, DeleteOutlined, BlockOutlined, BulbOutlined, ClockCircleOutlined, UserOutlined } from '@ant-design/icons';
2
- import { Input, Radio, Space, Row, Col, Button, Dropdown, Table, Empty, message, Form, Steps, Upload, Tooltip, Modal, Alert, Card, Skeleton, Popover, List, Typography, Tag, Checkbox, InputNumber, Select, Spin, Progress } from 'antd';
2
+ import { Input, Radio, Space, Row, Col, Button, Dropdown, Table, Empty, message, Form, Steps, Upload, Tooltip, Select, Modal, Alert, Card, Skeleton, Popover, List, Typography, Tag, Checkbox, InputNumber, Spin, Progress } from 'antd';
3
3
  import React, { useState, useEffect, useRef } from 'react';
4
4
  import { DateTime } from 'luxon';
5
5
  import { Buffer } from 'buffer';
@@ -736,7 +736,7 @@ var css_248z$d = "body {\n background-color: #f4f5fa;\n font-family: \"Inter\"
736
736
  styleInject(css_248z$d);
737
737
 
738
738
  var AddNewCompanyComponent = function (props) {
739
- var t = props.t, onNavigateToCompanyManagement = props.onNavigateToCompanyManagement, maximumImageSize = props.maximumImageSize, useConnection = props.useConnection, useUserContext = props.useUserContext, useLocation = props.useLocation;
739
+ var t = props.t, onNavigateToCompanyManagement = props.onNavigateToCompanyManagement, maximumImageSize = props.maximumImageSize, useConnection = props.useConnection, useUserContext = props.useUserContext, useLocation = props.useLocation, regionField = props.regionField;
740
740
  var formOne = Form.useForm()[0];
741
741
  var formTwo = Form.useForm()[0];
742
742
  var _a = useState(), stepOneData = _a[0], setStepOneData = _a[1];
@@ -749,6 +749,8 @@ var AddNewCompanyComponent = function (props) {
749
749
  var state = useLocation().state;
750
750
  var _f = useState([]), fileList = _f[0], setFileList = _f[1];
751
751
  var _g = useState([]), countries = _g[0], setCountries = _g[1];
752
+ var _h = useState(false), loadingList = _h[0], setLoadingList = _h[1];
753
+ var _j = useState([]), regionsList = _j[0], setRegionsList = _j[1];
752
754
  var getCountryList = function () { return __awaiter(void 0, void 0, void 0, function () {
753
755
  var response, alpha2Names;
754
756
  return __generator(this, function (_a) {
@@ -766,18 +768,50 @@ var AddNewCompanyComponent = function (props) {
766
768
  }
767
769
  });
768
770
  }); };
771
+ var getRegionList = function () { return __awaiter(void 0, void 0, void 0, function () {
772
+ var response, regionNames, error_1;
773
+ return __generator(this, function (_a) {
774
+ switch (_a.label) {
775
+ case 0:
776
+ setLoadingList(true);
777
+ _a.label = 1;
778
+ case 1:
779
+ _a.trys.push([1, 3, 4, 5]);
780
+ return [4 /*yield*/, post("national/organisation/regions", {
781
+ page: 1,
782
+ size: 100,
783
+ })];
784
+ case 2:
785
+ response = _a.sent();
786
+ if (response.data) {
787
+ regionNames = response.data.map(function (item) { return item.regionName; });
788
+ setRegionsList(__spreadArray(["National"], regionNames, true));
789
+ }
790
+ return [3 /*break*/, 5];
791
+ case 3:
792
+ error_1 = _a.sent();
793
+ console.log("Error in getting regions list", error_1);
794
+ return [3 /*break*/, 5];
795
+ case 4:
796
+ setLoadingList(false);
797
+ return [7 /*endfinally*/];
798
+ case 5: return [2 /*return*/];
799
+ }
800
+ });
801
+ }); };
769
802
  useEffect(function () {
770
803
  var _a, _b, _c;
771
804
  setIsUpdate((state === null || state === void 0 ? void 0 : state.record) ? true : false);
772
805
  getCountryList();
806
+ getRegionList();
773
807
  if ((_a = state === null || state === void 0 ? void 0 : state.record) === null || _a === void 0 ? void 0 : _a.logo) {
774
808
  setFileList([
775
809
  {
776
- uid: '1',
810
+ uid: "1",
777
811
  name: "".concat((_b = state === null || state === void 0 ? void 0 : state.record) === null || _b === void 0 ? void 0 : _b.name, ".png"),
778
- status: 'done',
812
+ status: "done",
779
813
  url: (_c = state === null || state === void 0 ? void 0 : state.record) === null || _c === void 0 ? void 0 : _c.logo,
780
- type: 'image/png',
814
+ type: "image/png",
781
815
  },
782
816
  ]);
783
817
  }
@@ -798,6 +832,13 @@ var AddNewCompanyComponent = function (props) {
798
832
  var onFinishStepOne = function (values) {
799
833
  nextOne(values);
800
834
  };
835
+ var onChangeRegion = function (values) {
836
+ if (values.includes("National")) {
837
+ var buyerCountryValues = regionsList;
838
+ var newBuyerValues = buyerCountryValues === null || buyerCountryValues === void 0 ? void 0 : buyerCountryValues.filter(function (item) { return item !== "National"; });
839
+ formOne.setFieldValue("regions", __spreadArray([], newBuyerValues, true));
840
+ }
841
+ };
801
842
  var getBase64 = function (file) {
802
843
  return new Promise(function (resolve, reject) {
803
844
  var reader = new FileReader();
@@ -807,7 +848,7 @@ var AddNewCompanyComponent = function (props) {
807
848
  });
808
849
  };
809
850
  var onFinishStepTwo = function (values) { return __awaiter(void 0, void 0, void 0, function () {
810
- var requestData, logoBase64, logoUrls, response, error_1;
851
+ var requestData, logoBase64, logoUrls, response, error_2;
811
852
  var _a, _b;
812
853
  return __generator(this, function (_c) {
813
854
  switch (_c.label) {
@@ -855,10 +896,10 @@ var AddNewCompanyComponent = function (props) {
855
896
  }
856
897
  return [3 /*break*/, 6];
857
898
  case 4:
858
- error_1 = _c.sent();
899
+ error_2 = _c.sent();
859
900
  message.open({
860
901
  type: 'error',
861
- content: "".concat(t('errorInAddUser'), " ").concat(error_1.message),
902
+ content: "".concat(t('errorInAddUser'), " ").concat(error_2.message),
862
903
  duration: 3,
863
904
  style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
864
905
  });
@@ -871,26 +912,40 @@ var AddNewCompanyComponent = function (props) {
871
912
  });
872
913
  }); };
873
914
  var onUpdateCompany = function () { return __awaiter(void 0, void 0, void 0, function () {
874
- var formOneValues, values, logoBase64, logoUrls, response, error_2;
875
- var _a, _b, _c, _d;
876
- return __generator(this, function (_e) {
877
- switch (_e.label) {
915
+ var formOneValues, values, logoBase64, logoUrls, response, error_3;
916
+ var _a, _b, _c, _d, _e, _f;
917
+ return __generator(this, function (_g) {
918
+ switch (_g.label) {
878
919
  case 0:
879
920
  setLoading(true);
880
921
  formOneValues = formOne.getFieldsValue();
881
922
  formOneValues.phoneNo = formatPhoneNumberIntl(formOneValues.phoneNo);
882
- _e.label = 1;
923
+ _g.label = 1;
883
924
  case 1:
884
- _e.trys.push([1, 5, , 6]);
885
- values = {
886
- companyId: (_a = state === null || state === void 0 ? void 0 : state.record) === null || _a === void 0 ? void 0 : _a.companyId,
887
- name: formOneValues.name,
888
- email: formOneValues.email,
889
- phoneNo: formOneValues.phoneNo,
890
- address: formOneValues.address,
891
- companyRole: (_b = state === null || state === void 0 ? void 0 : state.record) === null || _b === void 0 ? void 0 : _b.companyRole,
892
- };
893
- if (((_c = state === null || state === void 0 ? void 0 : state.record) === null || _c === void 0 ? void 0 : _c.companyRole) !== CompanyRole$1.GOVERNMENT) {
925
+ _g.trys.push([1, 5, , 6]);
926
+ values = {};
927
+ if (regionField) {
928
+ values = {
929
+ companyId: (_a = state === null || state === void 0 ? void 0 : state.record) === null || _a === void 0 ? void 0 : _a.companyId,
930
+ name: formOneValues.name,
931
+ email: formOneValues.email,
932
+ phoneNo: formOneValues.phoneNo,
933
+ address: formOneValues.address,
934
+ regions: formOneValues.regions,
935
+ companyRole: (_b = state === null || state === void 0 ? void 0 : state.record) === null || _b === void 0 ? void 0 : _b.companyRole,
936
+ };
937
+ }
938
+ else {
939
+ values = {
940
+ companyId: (_c = state === null || state === void 0 ? void 0 : state.record) === null || _c === void 0 ? void 0 : _c.companyId,
941
+ name: formOneValues.name,
942
+ email: formOneValues.email,
943
+ phoneNo: formOneValues.phoneNo,
944
+ address: formOneValues.address,
945
+ companyRole: (_d = state === null || state === void 0 ? void 0 : state.record) === null || _d === void 0 ? void 0 : _d.companyRole,
946
+ };
947
+ }
948
+ if (((_e = state === null || state === void 0 ? void 0 : state.record) === null || _e === void 0 ? void 0 : _e.companyRole) !== CompanyRole$1.GOVERNMENT) {
894
949
  values.taxId = formOneValues.taxId;
895
950
  }
896
951
  if (formOneValues.website) {
@@ -901,15 +956,15 @@ var AddNewCompanyComponent = function (props) {
901
956
  }
902
957
  if (!formOneValues.logo) return [3 /*break*/, 3];
903
958
  if (!(formOneValues.logo.length !== 0)) return [3 /*break*/, 3];
904
- return [4 /*yield*/, getBase64((_d = formOneValues.logo[0]) === null || _d === void 0 ? void 0 : _d.originFileObj)];
959
+ return [4 /*yield*/, getBase64((_f = formOneValues.logo[0]) === null || _f === void 0 ? void 0 : _f.originFileObj)];
905
960
  case 2:
906
- logoBase64 = _e.sent();
961
+ logoBase64 = _g.sent();
907
962
  logoUrls = logoBase64.split(',');
908
963
  values.logo = logoUrls[1];
909
- _e.label = 3;
964
+ _g.label = 3;
910
965
  case 3: return [4 /*yield*/, put('national/organisation/update', values)];
911
966
  case 4:
912
- response = _e.sent();
967
+ response = _g.sent();
913
968
  if (response.status === 200 || response.status === 201) {
914
969
  setUserInfo({
915
970
  companyLogo: response.data.logo,
@@ -925,10 +980,10 @@ var AddNewCompanyComponent = function (props) {
925
980
  setLoading(false);
926
981
  return [3 /*break*/, 6];
927
982
  case 5:
928
- error_2 = _e.sent();
983
+ error_3 = _g.sent();
929
984
  message.open({
930
985
  type: 'error',
931
- content: "".concat(t('errorInUpdatingCompany'), " ").concat(error_2.message),
986
+ content: "".concat(t('errorInUpdatingCompany'), " ").concat(error_3.message),
932
987
  duration: 3,
933
988
  style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
934
989
  });
@@ -942,7 +997,7 @@ var AddNewCompanyComponent = function (props) {
942
997
  onNavigateToCompanyManagement();
943
998
  };
944
999
  var CompanyDetailsForm = function () {
945
- var _a, _b, _c, _d, _e, _f, _g, _h;
1000
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
946
1001
  var companyRole = (_a = state === null || state === void 0 ? void 0 : state.record) === null || _a === void 0 ? void 0 : _a.companyRole;
947
1002
  var companyRoleClassName = companyRole === CompanyRole$1.CERTIFIER
948
1003
  ? 'certifier'
@@ -1122,16 +1177,23 @@ var AddNewCompanyComponent = function (props) {
1122
1177
  },
1123
1178
  ] },
1124
1179
  React.createElement(PhoneInput, { placeholder: "Phone number", international: true, value: formatPhoneNumberIntl(contactNoInput), defaultCountry: "LK", countryCallingCodeEditable: false, onChange: function (v) { }, countries: countries })),
1125
- React.createElement(Form.Item, { name: "address", label: "Address", initialValue: (_h = state === null || state === void 0 ? void 0 : state.record) === null || _h === void 0 ? void 0 : _h.address, rules: [
1126
- { required: true, message: '' },
1180
+ regionField && (React.createElement(Form.Item, { label: t("region"), name: "regions", initialValue: (_h = state === null || state === void 0 ? void 0 : state.record) === null || _h === void 0 ? void 0 : _h.regions, rules: [
1181
+ {
1182
+ required: true,
1183
+ message: "".concat(t("region"), " ").concat(t("isRequired")),
1184
+ },
1185
+ ] },
1186
+ React.createElement(Select, { mode: "multiple", size: "large", maxTagCount: 2, onChange: onChangeRegion, loading: loadingList }, regionsList.map(function (region) { return (React.createElement(Select.Option, { value: region }, region)); })))),
1187
+ React.createElement(Form.Item, { name: "address", label: "Address", initialValue: (_j = state === null || state === void 0 ? void 0 : state.record) === null || _j === void 0 ? void 0 : _j.address, rules: [
1188
+ { required: true, message: "" },
1127
1189
  {
1128
1190
  validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
1129
1191
  return __generator(this, function (_a) {
1130
- if (String(value).trim() === '' ||
1192
+ if (String(value).trim() === "" ||
1131
1193
  String(value).trim() === undefined ||
1132
1194
  value === null ||
1133
1195
  value === undefined) {
1134
- throw new Error("Address ".concat(t('isRequired')));
1196
+ throw new Error("Address ".concat(t("isRequired")));
1135
1197
  }
1136
1198
  return [2 /*return*/];
1137
1199
  });
@@ -1277,7 +1339,7 @@ var OrganisationStatus = function (props) {
1277
1339
  };
1278
1340
 
1279
1341
  var CompanyProfileComponent = function (props) {
1280
- var t = props.t, useAbilityContext = props.useAbilityContext, useLocation = props.useLocation, useConnection = props.useConnection, onNavigateToCompanyManagement = props.onNavigateToCompanyManagement, onNavigateToCompanyEdit = props.onNavigateToCompanyEdit;
1342
+ var t = props.t, useAbilityContext = props.useAbilityContext, useLocation = props.useLocation, useConnection = props.useConnection, onNavigateToCompanyManagement = props.onNavigateToCompanyManagement, onNavigateToCompanyEdit = props.onNavigateToCompanyEdit, regionField = props.regionField;
1281
1343
  var _a = useConnection(), get = _a.get, put = _a.put;
1282
1344
  var _b = useState([]), companyDetails = _b[0], setCompanyDetails = _b[1];
1283
1345
  var state = useLocation().state;
@@ -1469,6 +1531,11 @@ var CompanyProfileComponent = function (props) {
1469
1531
  React.createElement(Row, { className: "field" },
1470
1532
  React.createElement(Col, { span: 12, className: "field-key" }, t("companyProfile:address")),
1471
1533
  React.createElement(Col, { span: 12, className: "field-value" }, companyDetails.address ? companyDetails.address : "-")),
1534
+ regionField && (React.createElement(Row, { className: "field" },
1535
+ React.createElement(Col, { span: 12, className: "field-key" }, t("companyProfile:region")),
1536
+ React.createElement(Col, { span: 12, className: "field-value" }, companyDetails.regions
1537
+ ? companyDetails.regions.join(", ")
1538
+ : "-"))),
1472
1539
  React.createElement(Row, { className: "field" },
1473
1540
  React.createElement(Col, { span: 12, className: "field-key" }, t("companyProfile:programmeCount")),
1474
1541
  React.createElement(Col, { span: 12, className: "field-value" }, companyDetails.programmeCount