@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.
package/dist/cjs/index.js CHANGED
@@ -756,7 +756,7 @@ var css_248z$d = "body {\n background-color: #f4f5fa;\n font-family: \"Inter\"
756
756
  styleInject(css_248z$d);
757
757
 
758
758
  var AddNewCompanyComponent = function (props) {
759
- var t = props.t, onNavigateToCompanyManagement = props.onNavigateToCompanyManagement, maximumImageSize = props.maximumImageSize, useConnection = props.useConnection, useUserContext = props.useUserContext, useLocation = props.useLocation;
759
+ var t = props.t, onNavigateToCompanyManagement = props.onNavigateToCompanyManagement, maximumImageSize = props.maximumImageSize, useConnection = props.useConnection, useUserContext = props.useUserContext, useLocation = props.useLocation, regionField = props.regionField;
760
760
  var formOne = antd.Form.useForm()[0];
761
761
  var formTwo = antd.Form.useForm()[0];
762
762
  var _a = React.useState(), stepOneData = _a[0], setStepOneData = _a[1];
@@ -769,6 +769,8 @@ var AddNewCompanyComponent = function (props) {
769
769
  var state = useLocation().state;
770
770
  var _f = React.useState([]), fileList = _f[0], setFileList = _f[1];
771
771
  var _g = React.useState([]), countries = _g[0], setCountries = _g[1];
772
+ var _h = React.useState(false), loadingList = _h[0], setLoadingList = _h[1];
773
+ var _j = React.useState([]), regionsList = _j[0], setRegionsList = _j[1];
772
774
  var getCountryList = function () { return __awaiter(void 0, void 0, void 0, function () {
773
775
  var response, alpha2Names;
774
776
  return __generator(this, function (_a) {
@@ -786,18 +788,50 @@ var AddNewCompanyComponent = function (props) {
786
788
  }
787
789
  });
788
790
  }); };
791
+ var getRegionList = function () { return __awaiter(void 0, void 0, void 0, function () {
792
+ var response, regionNames, error_1;
793
+ return __generator(this, function (_a) {
794
+ switch (_a.label) {
795
+ case 0:
796
+ setLoadingList(true);
797
+ _a.label = 1;
798
+ case 1:
799
+ _a.trys.push([1, 3, 4, 5]);
800
+ return [4 /*yield*/, post("national/organisation/regions", {
801
+ page: 1,
802
+ size: 100,
803
+ })];
804
+ case 2:
805
+ response = _a.sent();
806
+ if (response.data) {
807
+ regionNames = response.data.map(function (item) { return item.regionName; });
808
+ setRegionsList(__spreadArray(["National"], regionNames, true));
809
+ }
810
+ return [3 /*break*/, 5];
811
+ case 3:
812
+ error_1 = _a.sent();
813
+ console.log("Error in getting regions list", error_1);
814
+ return [3 /*break*/, 5];
815
+ case 4:
816
+ setLoadingList(false);
817
+ return [7 /*endfinally*/];
818
+ case 5: return [2 /*return*/];
819
+ }
820
+ });
821
+ }); };
789
822
  React.useEffect(function () {
790
823
  var _a, _b, _c;
791
824
  setIsUpdate((state === null || state === void 0 ? void 0 : state.record) ? true : false);
792
825
  getCountryList();
826
+ getRegionList();
793
827
  if ((_a = state === null || state === void 0 ? void 0 : state.record) === null || _a === void 0 ? void 0 : _a.logo) {
794
828
  setFileList([
795
829
  {
796
- uid: '1',
830
+ uid: "1",
797
831
  name: "".concat((_b = state === null || state === void 0 ? void 0 : state.record) === null || _b === void 0 ? void 0 : _b.name, ".png"),
798
- status: 'done',
832
+ status: "done",
799
833
  url: (_c = state === null || state === void 0 ? void 0 : state.record) === null || _c === void 0 ? void 0 : _c.logo,
800
- type: 'image/png',
834
+ type: "image/png",
801
835
  },
802
836
  ]);
803
837
  }
@@ -818,6 +852,13 @@ var AddNewCompanyComponent = function (props) {
818
852
  var onFinishStepOne = function (values) {
819
853
  nextOne(values);
820
854
  };
855
+ var onChangeRegion = function (values) {
856
+ if (values.includes("National")) {
857
+ var buyerCountryValues = regionsList;
858
+ var newBuyerValues = buyerCountryValues === null || buyerCountryValues === void 0 ? void 0 : buyerCountryValues.filter(function (item) { return item !== "National"; });
859
+ formOne.setFieldValue("regions", __spreadArray([], newBuyerValues, true));
860
+ }
861
+ };
821
862
  var getBase64 = function (file) {
822
863
  return new Promise(function (resolve, reject) {
823
864
  var reader = new FileReader();
@@ -827,7 +868,7 @@ var AddNewCompanyComponent = function (props) {
827
868
  });
828
869
  };
829
870
  var onFinishStepTwo = function (values) { return __awaiter(void 0, void 0, void 0, function () {
830
- var requestData, logoBase64, logoUrls, response, error_1;
871
+ var requestData, logoBase64, logoUrls, response, error_2;
831
872
  var _a, _b;
832
873
  return __generator(this, function (_c) {
833
874
  switch (_c.label) {
@@ -875,10 +916,10 @@ var AddNewCompanyComponent = function (props) {
875
916
  }
876
917
  return [3 /*break*/, 6];
877
918
  case 4:
878
- error_1 = _c.sent();
919
+ error_2 = _c.sent();
879
920
  antd.message.open({
880
921
  type: 'error',
881
- content: "".concat(t('errorInAddUser'), " ").concat(error_1.message),
922
+ content: "".concat(t('errorInAddUser'), " ").concat(error_2.message),
882
923
  duration: 3,
883
924
  style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
884
925
  });
@@ -891,26 +932,40 @@ var AddNewCompanyComponent = function (props) {
891
932
  });
892
933
  }); };
893
934
  var onUpdateCompany = function () { return __awaiter(void 0, void 0, void 0, function () {
894
- var formOneValues, values, logoBase64, logoUrls, response, error_2;
895
- var _a, _b, _c, _d;
896
- return __generator(this, function (_e) {
897
- switch (_e.label) {
935
+ var formOneValues, values, logoBase64, logoUrls, response, error_3;
936
+ var _a, _b, _c, _d, _e, _f;
937
+ return __generator(this, function (_g) {
938
+ switch (_g.label) {
898
939
  case 0:
899
940
  setLoading(true);
900
941
  formOneValues = formOne.getFieldsValue();
901
942
  formOneValues.phoneNo = PhoneInput.formatPhoneNumberIntl(formOneValues.phoneNo);
902
- _e.label = 1;
943
+ _g.label = 1;
903
944
  case 1:
904
- _e.trys.push([1, 5, , 6]);
905
- values = {
906
- companyId: (_a = state === null || state === void 0 ? void 0 : state.record) === null || _a === void 0 ? void 0 : _a.companyId,
907
- name: formOneValues.name,
908
- email: formOneValues.email,
909
- phoneNo: formOneValues.phoneNo,
910
- address: formOneValues.address,
911
- companyRole: (_b = state === null || state === void 0 ? void 0 : state.record) === null || _b === void 0 ? void 0 : _b.companyRole,
912
- };
913
- if (((_c = state === null || state === void 0 ? void 0 : state.record) === null || _c === void 0 ? void 0 : _c.companyRole) !== exports.CompanyRole.GOVERNMENT) {
945
+ _g.trys.push([1, 5, , 6]);
946
+ values = {};
947
+ if (regionField) {
948
+ values = {
949
+ companyId: (_a = state === null || state === void 0 ? void 0 : state.record) === null || _a === void 0 ? void 0 : _a.companyId,
950
+ name: formOneValues.name,
951
+ email: formOneValues.email,
952
+ phoneNo: formOneValues.phoneNo,
953
+ address: formOneValues.address,
954
+ regions: formOneValues.regions,
955
+ companyRole: (_b = state === null || state === void 0 ? void 0 : state.record) === null || _b === void 0 ? void 0 : _b.companyRole,
956
+ };
957
+ }
958
+ else {
959
+ values = {
960
+ companyId: (_c = state === null || state === void 0 ? void 0 : state.record) === null || _c === void 0 ? void 0 : _c.companyId,
961
+ name: formOneValues.name,
962
+ email: formOneValues.email,
963
+ phoneNo: formOneValues.phoneNo,
964
+ address: formOneValues.address,
965
+ companyRole: (_d = state === null || state === void 0 ? void 0 : state.record) === null || _d === void 0 ? void 0 : _d.companyRole,
966
+ };
967
+ }
968
+ if (((_e = state === null || state === void 0 ? void 0 : state.record) === null || _e === void 0 ? void 0 : _e.companyRole) !== exports.CompanyRole.GOVERNMENT) {
914
969
  values.taxId = formOneValues.taxId;
915
970
  }
916
971
  if (formOneValues.website) {
@@ -921,15 +976,15 @@ var AddNewCompanyComponent = function (props) {
921
976
  }
922
977
  if (!formOneValues.logo) return [3 /*break*/, 3];
923
978
  if (!(formOneValues.logo.length !== 0)) return [3 /*break*/, 3];
924
- return [4 /*yield*/, getBase64((_d = formOneValues.logo[0]) === null || _d === void 0 ? void 0 : _d.originFileObj)];
979
+ return [4 /*yield*/, getBase64((_f = formOneValues.logo[0]) === null || _f === void 0 ? void 0 : _f.originFileObj)];
925
980
  case 2:
926
- logoBase64 = _e.sent();
981
+ logoBase64 = _g.sent();
927
982
  logoUrls = logoBase64.split(',');
928
983
  values.logo = logoUrls[1];
929
- _e.label = 3;
984
+ _g.label = 3;
930
985
  case 3: return [4 /*yield*/, put('national/organisation/update', values)];
931
986
  case 4:
932
- response = _e.sent();
987
+ response = _g.sent();
933
988
  if (response.status === 200 || response.status === 201) {
934
989
  setUserInfo({
935
990
  companyLogo: response.data.logo,
@@ -945,10 +1000,10 @@ var AddNewCompanyComponent = function (props) {
945
1000
  setLoading(false);
946
1001
  return [3 /*break*/, 6];
947
1002
  case 5:
948
- error_2 = _e.sent();
1003
+ error_3 = _g.sent();
949
1004
  antd.message.open({
950
1005
  type: 'error',
951
- content: "".concat(t('errorInUpdatingCompany'), " ").concat(error_2.message),
1006
+ content: "".concat(t('errorInUpdatingCompany'), " ").concat(error_3.message),
952
1007
  duration: 3,
953
1008
  style: { textAlign: 'right', marginRight: 15, marginTop: 10 },
954
1009
  });
@@ -962,7 +1017,7 @@ var AddNewCompanyComponent = function (props) {
962
1017
  onNavigateToCompanyManagement();
963
1018
  };
964
1019
  var CompanyDetailsForm = function () {
965
- var _a, _b, _c, _d, _e, _f, _g, _h;
1020
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
966
1021
  var companyRole = (_a = state === null || state === void 0 ? void 0 : state.record) === null || _a === void 0 ? void 0 : _a.companyRole;
967
1022
  var companyRoleClassName = companyRole === exports.CompanyRole.CERTIFIER
968
1023
  ? 'certifier'
@@ -1142,16 +1197,23 @@ var AddNewCompanyComponent = function (props) {
1142
1197
  },
1143
1198
  ] },
1144
1199
  React.createElement(PhoneInput, { placeholder: "Phone number", international: true, value: PhoneInput.formatPhoneNumberIntl(contactNoInput), defaultCountry: "LK", countryCallingCodeEditable: false, onChange: function (v) { }, countries: countries })),
1145
- React.createElement(antd.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: [
1146
- { required: true, message: '' },
1200
+ regionField && (React.createElement(antd.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: [
1201
+ {
1202
+ required: true,
1203
+ message: "".concat(t("region"), " ").concat(t("isRequired")),
1204
+ },
1205
+ ] },
1206
+ React.createElement(antd.Select, { mode: "multiple", size: "large", maxTagCount: 2, onChange: onChangeRegion, loading: loadingList }, regionsList.map(function (region) { return (React.createElement(antd.Select.Option, { value: region }, region)); })))),
1207
+ React.createElement(antd.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: [
1208
+ { required: true, message: "" },
1147
1209
  {
1148
1210
  validator: function (rule, value) { return __awaiter(void 0, void 0, void 0, function () {
1149
1211
  return __generator(this, function (_a) {
1150
- if (String(value).trim() === '' ||
1212
+ if (String(value).trim() === "" ||
1151
1213
  String(value).trim() === undefined ||
1152
1214
  value === null ||
1153
1215
  value === undefined) {
1154
- throw new Error("Address ".concat(t('isRequired')));
1216
+ throw new Error("Address ".concat(t("isRequired")));
1155
1217
  }
1156
1218
  return [2 /*return*/];
1157
1219
  });
@@ -1297,7 +1359,7 @@ var OrganisationStatus = function (props) {
1297
1359
  };
1298
1360
 
1299
1361
  var CompanyProfileComponent = function (props) {
1300
- var t = props.t, useAbilityContext = props.useAbilityContext, useLocation = props.useLocation, useConnection = props.useConnection, onNavigateToCompanyManagement = props.onNavigateToCompanyManagement, onNavigateToCompanyEdit = props.onNavigateToCompanyEdit;
1362
+ var t = props.t, useAbilityContext = props.useAbilityContext, useLocation = props.useLocation, useConnection = props.useConnection, onNavigateToCompanyManagement = props.onNavigateToCompanyManagement, onNavigateToCompanyEdit = props.onNavigateToCompanyEdit, regionField = props.regionField;
1301
1363
  var _a = useConnection(), get = _a.get, put = _a.put;
1302
1364
  var _b = React.useState([]), companyDetails = _b[0], setCompanyDetails = _b[1];
1303
1365
  var state = useLocation().state;
@@ -1489,6 +1551,11 @@ var CompanyProfileComponent = function (props) {
1489
1551
  React.createElement(antd.Row, { className: "field" },
1490
1552
  React.createElement(antd.Col, { span: 12, className: "field-key" }, t("companyProfile:address")),
1491
1553
  React.createElement(antd.Col, { span: 12, className: "field-value" }, companyDetails.address ? companyDetails.address : "-")),
1554
+ regionField && (React.createElement(antd.Row, { className: "field" },
1555
+ React.createElement(antd.Col, { span: 12, className: "field-key" }, t("companyProfile:region")),
1556
+ React.createElement(antd.Col, { span: 12, className: "field-value" }, companyDetails.regions
1557
+ ? companyDetails.regions.join(", ")
1558
+ : "-"))),
1492
1559
  React.createElement(antd.Row, { className: "field" },
1493
1560
  React.createElement(antd.Col, { span: 12, className: "field-key" }, t("companyProfile:programmeCount")),
1494
1561
  React.createElement(antd.Col, { span: 12, className: "field-value" }, companyDetails.programmeCount