@djb25/digit-ui-module-vendor 1.0.8 → 1.0.10

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,5 +1,5 @@
1
1
  import { Header, SearchForm, SearchField, Dropdown as Dropdown$2, MobileNumber, CardLabelError, DatePicker as DatePicker$3, SubmitBar, Card, Table, Loader, Toast, AppContainer, ModuleHeader, ArrowLeft, PrivateRoute, HomeIcon, PropertyHouse, EmployeeModuleCard, Stepper, FormComposer, TickMark, FormStep, CardLabel, TextInput, LabelFieldPair, UploadFile, CardSubHeader, CardText, RadioOrSelect, ShippingTruck, CheckBox, RadioButtons, CloseSvg, Localities, RemoveableTag, ActionBar, ApplyFilterBar, AddIcon, Menu, Label, LinkLabel, ToggleSwitch, CardSectionHeader, StatusTable, Row, EditIcon, DeleteIcon, Modal, InfoIcon, CardHeader, LinkButton, Banner } from '@djb25/digit-ui-react-components';
2
- import React, { useEffect, useMemo, useCallback, useState, useRef, Fragment } from 'react';
2
+ import React, { useEffect, useMemo, useCallback, useState, Fragment } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { useParams, useLocation, Switch, Link, useHistory, useRouteMatch, Route, Redirect } from 'react-router-dom';
5
5
  import { useForm, Controller } from 'react-hook-form';
@@ -385,9 +385,8 @@ const EmployeeApp = ({
385
385
  className: "employee-form"
386
386
  }, /*#__PURE__*/React.createElement(PrivateRoute, {
387
387
  path: `${path}/registry/new-vendor`,
388
- component: () => /*#__PURE__*/React.createElement(AddVendor, {
389
- parentRoute: path
390
- })
388
+ component: AddVendor,
389
+ parentRoute: path
391
390
  }), /*#__PURE__*/React.createElement(PrivateRoute, {
392
391
  path: `${path}/search-vendor`,
393
392
  component: () => /*#__PURE__*/React.createElement(SearchVendor, {
@@ -613,6 +612,25 @@ const VendorConfig = (t, disabled = false) => {
613
612
  defaultValue: "",
614
613
  className: "payment-form-text-input-correction"
615
614
  }
615
+ }, {
616
+ label: "ES_VENDOR_REGISTRY_SERVICE_TYPE",
617
+ isMandatory: true,
618
+ type: "component",
619
+ key: "serviceType",
620
+ component: "SelectServiceType",
621
+ disable: disabled,
622
+ populators: {
623
+ name: "serviceType",
624
+ defaultValue: {
625
+ code: "WT",
626
+ name: "WT",
627
+ i18nKey: "WT"
628
+ }
629
+ },
630
+ texts: {
631
+ header: "CS_COMMON_CHOOSE_SERVICE_TYPE",
632
+ submitBarLabel: "CS_COMMON_NEXT"
633
+ }
616
634
  }]
617
635
  }, {
618
636
  head: "ES_FSM_REGISTRY_NEW_ADDRESS_DETAILS",
@@ -710,12 +728,12 @@ const AddVendor = ({
710
728
  const [currentStep, setCurrentStep] = useState(1);
711
729
  const [showToast, setShowToast] = useState(null);
712
730
  const [canSubmit, setCanSubmit] = useState(false);
713
- const step1DataRef = useRef({});
731
+ const [step1Data, setStep1Data] = useState({});
714
732
  const [mutationHappened, setMutationHappened, clear] = Digit.Hooks.useSessionStorage("FSM_MUTATION_HAPPENED", false);
715
733
  const [errorInfo, setErrorInfo, clearError] = Digit.Hooks.useSessionStorage("FSM_ERROR_DATA", false);
716
734
  const [successData, setsuccessData, clearSuccessData] = Digit.Hooks.useSessionStorage("FSM_MUTATION_SUCCESS_DATA", false);
717
735
  const {
718
- isLoading: isLoading,
736
+ isLoading,
719
737
  isError: vendorCreateError,
720
738
  data: updateResponse,
721
739
  error: updateError,
@@ -728,6 +746,11 @@ const AddVendor = ({
728
746
  }, []);
729
747
  const Config = VendorConfig(t);
730
748
  const defaultValues = {
749
+ serviceType: {
750
+ code: "WT",
751
+ name: "WT",
752
+ i18nKey: "WT"
753
+ },
731
754
  tripData: {
732
755
  noOfTrips: 1,
733
756
  amountPerTrip: null,
@@ -742,8 +765,8 @@ const AddVendor = ({
742
765
  label: "ES_FSM_REGISTRY_NEW_ADDRESS_DETAILS"
743
766
  }];
744
767
  const onFormValueChange = (setValue, formData) => {
745
- var _formData$selectGende;
746
- if (formData !== null && formData !== void 0 && formData.vendorName && formData !== null && formData !== void 0 && formData.phone && formData !== null && formData !== void 0 && (_formData$selectGende = formData.selectGender) !== null && _formData$selectGende !== void 0 && _formData$selectGende.code) {
768
+ var _formData$selectGende, _formData$serviceType;
769
+ if (formData !== null && formData !== void 0 && formData.vendorName && formData !== null && formData !== void 0 && formData.phone && formData !== null && formData !== void 0 && (_formData$selectGende = formData.selectGender) !== null && _formData$selectGende !== void 0 && _formData$selectGende.code && formData !== null && formData !== void 0 && (_formData$serviceType = formData.serviceType) !== null && _formData$serviceType !== void 0 && _formData$serviceType.code) {
747
770
  setCanSubmit(true);
748
771
  } else {
749
772
  setCanSubmit(false);
@@ -755,12 +778,12 @@ const AddVendor = ({
755
778
  const onSubmit = data => {
756
779
  var _mergedData$street, _mergedData$doorNo, _mergedData$plotNo, _mergedData$landmark, _mergedData$address, _mergedData$address$c, _mergedData$address2, _mergedData$address2$, _mergedData$address3, _mergedData$address3$, _mergedData$address4, _mergedData$address4$, _mergedData$buildingN, _mergedData$address5, _mergedData$address5$, _mergedData$address6, _mergedData$address6$, _mergedData$address7, _mergedData$address7$, _mergedData$selectGen, _mergedData$serviceTy, _mergedData$address8, _mergedData$address9;
757
780
  if (currentStep === 1) {
758
- step1DataRef.current = data;
781
+ setStep1Data(data);
759
782
  setCurrentStep(2);
760
783
  return;
761
784
  }
762
785
  const mergedData = {
763
- ...step1DataRef.current,
786
+ ...step1Data,
764
787
  ...data
765
788
  };
766
789
  const name = mergedData === null || mergedData === void 0 ? void 0 : mergedData.vendorName;
@@ -831,7 +854,7 @@ const AddVendor = ({
831
854
  }
832
855
  };
833
856
  mutate(formData, {
834
- onError: (error, variables) => {
857
+ onError: error => {
835
858
  setShowToast({
836
859
  key: "error",
837
860
  action: error
@@ -850,28 +873,28 @@ const AddVendor = ({
850
873
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Stepper, {
851
874
  steps: steps,
852
875
  currentStep: currentStep - 1,
853
- onStepClick: step => setCurrentStep(step + 1),
876
+ onStepClick: () => {},
854
877
  t: t
855
878
  }), /*#__PURE__*/React.createElement("div", {
856
879
  style: {
857
880
  flex: "1",
858
881
  overflowY: "auto"
859
882
  }
860
- }, currentStep === 1 &&
861
- /*#__PURE__*/
862
- React.createElement(FormComposer, {
883
+ }, currentStep === 1 && /*#__PURE__*/React.createElement(FormComposer, {
884
+ isDisabled: !canSubmit,
863
885
  label: t("CS_COMMON_NEXT"),
864
886
  config: vendorStepConfig.filter(i => !i.hideInEmployee).map(config => ({
865
887
  ...config,
866
888
  body: config.body.filter(a => !a.hideInEmployee)
867
889
  })),
868
890
  onSubmit: onSubmit,
869
- defaultValues: defaultValues,
891
+ defaultValues: {
892
+ ...defaultValues,
893
+ ...step1Data
894
+ },
870
895
  onFormValueChange: onFormValueChange,
871
896
  noBreakLine: true
872
- }), currentStep === 2 &&
873
- /*#__PURE__*/
874
- React.createElement(FormComposer, {
897
+ }), currentStep === 2 && /*#__PURE__*/React.createElement(FormComposer, {
875
898
  label: t("ES_COMMON_APPLICATION_SUBMIT"),
876
899
  config: addressStepConfig.filter(i => !i.hideInEmployee).map(config => ({
877
900
  ...config,
@@ -879,7 +902,7 @@ const AddVendor = ({
879
902
  })),
880
903
  onSubmit: onSubmit,
881
904
  defaultValues: defaultValues,
882
- onFormValueChange: onFormValueChange,
905
+ onFormValueChange: (setValue, formData) => {},
883
906
  noBreakLine: true
884
907
  }), showToast && /*#__PURE__*/React.createElement(Toast, {
885
908
  error: showToast.key === "error",
@@ -8211,6 +8234,7 @@ const VendorInbox = props => {
8211
8234
  const [tableData, setTableData] = useState([]);
8212
8235
  const [showToast, setShowToast] = useState(null);
8213
8236
  const [vendors, setVendors] = useState([]);
8237
+ const [drivers, setDrivers] = useState([]);
8214
8238
  const queryClient = useQueryClient();
8215
8239
  const [address, setAddress] = useState();
8216
8240
  const {
@@ -8226,6 +8250,18 @@ const VendorInbox = props => {
8226
8250
  }, {
8227
8251
  enabled: false
8228
8252
  });
8253
+ const {
8254
+ data: driverData,
8255
+ refetch: refetchDriver
8256
+ } = Digit.Hooks.fsm.useDriverSearch({
8257
+ tenantId,
8258
+ filters: {
8259
+ sortBy: "name",
8260
+ sortOrder: "ASC",
8261
+ status: "ACTIVE",
8262
+ driverWithNoVendor: true
8263
+ }
8264
+ });
8229
8265
  const {
8230
8266
  isLoading: isUpdateVendorLoading,
8231
8267
  isError: vendorUpdateError,
@@ -8252,7 +8288,10 @@ const VendorInbox = props => {
8252
8288
  setTableData((props === null || props === void 0 ? void 0 : (_props$data = props.data) === null || _props$data === void 0 ? void 0 : _props$data.table) || []);
8253
8289
  }, [props]);
8254
8290
  useEffect(() => {
8255
- if (props.selectedTab === "DRIVER" || props.selectedTab === "VEHICLE") refetchVendor();
8291
+ if (props.selectedTab === "DRIVER" || props.selectedTab === "VEHICLE") {
8292
+ refetchVendor();
8293
+ refetchDriver();
8294
+ }
8256
8295
  }, [props.selectedTab]);
8257
8296
  useEffect(() => {
8258
8297
  if (vendorData) {
@@ -8260,6 +8299,11 @@ const VendorInbox = props => {
8260
8299
  setVendors(vendors);
8261
8300
  }
8262
8301
  }, [vendorData]);
8302
+ useEffect(() => {
8303
+ if (driverData) {
8304
+ setDrivers(driverData.driver || []);
8305
+ }
8306
+ }, [driverData]);
8263
8307
  const closeToast = () => {
8264
8308
  setShowToast(null);
8265
8309
  };
@@ -8398,6 +8442,34 @@ const VendorInbox = props => {
8398
8442
  }
8399
8443
  });
8400
8444
  };
8445
+ const onDriverSelect = (row, selectedOption) => {
8446
+ let vehicleData = row.original;
8447
+ let selectedDriver = selectedOption;
8448
+ const formData = {
8449
+ vehicle: {
8450
+ ...vehicleData,
8451
+ driverData: selectedDriver
8452
+ }
8453
+ };
8454
+ mutateVehicle(formData, {
8455
+ onError: (error, variables) => {
8456
+ setShowToast({
8457
+ key: "error",
8458
+ action: error
8459
+ });
8460
+ setTimeout(closeToast, 5000);
8461
+ },
8462
+ onSuccess: (data, variables) => {
8463
+ setShowToast({
8464
+ key: "success",
8465
+ action: "VEHICLE"
8466
+ });
8467
+ queryClient.invalidateQueries("FSM_VEICLES_SEARCH");
8468
+ props.refetchData();
8469
+ setTimeout(closeToast, 3000);
8470
+ }
8471
+ });
8472
+ };
8401
8473
  const onSelectAdd = () => {
8402
8474
  switch (props.selectedTab) {
8403
8475
  case "VENDOR":
@@ -8422,18 +8494,12 @@ const VendorInbox = props => {
8422
8494
  } = Digit.Hooks.vendor.useEmpvendorCommonSearch({
8423
8495
  tenantId,
8424
8496
  filters: {
8425
- vendorIds: vendorIds
8497
+ vendorIds: vendorIds === null || vendorIds === void 0 ? void 0 : vendorIds.join(","),
8498
+ vendorId: vendorIds === null || vendorIds === void 0 ? void 0 : vendorIds.join(",")
8426
8499
  }
8427
8500
  }, {
8428
8501
  enabled: (vendorIds === null || vendorIds === void 0 ? void 0 : vendorIds.length) > 0
8429
8502
  });
8430
- const hasAdditionalDetails = vendorId => {
8431
- var _additionalVendorData;
8432
- return additionalVendorData === null || additionalVendorData === void 0 ? void 0 : (_additionalVendorData = additionalVendorData.VendorDetails) === null || _additionalVendorData === void 0 ? void 0 : _additionalVendorData.some(v => {
8433
- var _v$vendorAdditionalDe;
8434
- return ((_v$vendorAdditionalDe = v.vendorAdditionalDetails) === null || _v$vendorAdditionalDe === void 0 ? void 0 : _v$vendorAdditionalDe.vendorId) === vendorId;
8435
- });
8436
- };
8437
8503
  const columns = React.useMemo(() => {
8438
8504
  switch (props.selectedTab) {
8439
8505
  case "VENDOR":
@@ -8500,21 +8566,25 @@ const VendorInbox = props => {
8500
8566
  Cell: ({
8501
8567
  row
8502
8568
  }) => {
8503
- var _row$original4;
8569
+ var _row$original4, _additionalVendorData;
8504
8570
  const vendorId = (_row$original4 = row.original) === null || _row$original4 === void 0 ? void 0 : _row$original4.id;
8505
- const hasDetails = hasAdditionalDetails(vendorId);
8506
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
8507
- className: "link"
8508
- }, /*#__PURE__*/React.createElement(Link, {
8571
+ if (!additionalVendorData) {
8572
+ return /*#__PURE__*/React.createElement("span", null, "Loading...");
8573
+ }
8574
+ const hasDetails = additionalVendorData === null || additionalVendorData === void 0 ? void 0 : (_additionalVendorData = additionalVendorData.VendorDetails) === null || _additionalVendorData === void 0 ? void 0 : _additionalVendorData.some(item => {
8575
+ var _item$vendorAdditiona;
8576
+ return (item === null || item === void 0 ? void 0 : (_item$vendorAdditiona = item.vendorAdditionalDetails) === null || _item$vendorAdditiona === void 0 ? void 0 : _item$vendorAdditiona.vendorId) === vendorId;
8577
+ });
8578
+ console.log(hasDetails, "ytgyg");
8579
+ return /*#__PURE__*/React.createElement(Link, {
8509
8580
  to: hasDetails ? "/digit-ui/employee/vendor/registry/additionaldetails/info?vendorId=" + vendorId : "/digit-ui/employee/vendor/registry/additionaldetails/vendor-details?vendorId=" + vendorId
8510
8581
  }, /*#__PURE__*/React.createElement("button", {
8511
8582
  className: "submit-bar",
8512
- type: "button",
8513
8583
  style: {
8514
- color: "white",
8515
- backgroundColor: hasDetails ? "#417505" : "#F47738"
8584
+ backgroundColor: hasDetails ? "#417505" : "#F47738",
8585
+ color: "white"
8516
8586
  }
8517
- }, hasDetails ? t("ES_VENDOR_VIEW_DETAILS") : t("ES_VENDOR_ADD_DETAILS")))));
8587
+ }, hasDetails ? "View Details" : "Add Details"));
8518
8588
  }
8519
8589
  }];
8520
8590
  case "VEHICLE":
@@ -8584,9 +8654,36 @@ const VendorInbox = props => {
8584
8654
  name: `switch-${row.id}`
8585
8655
  });
8586
8656
  }
8657
+ }, {
8658
+ Header: t("ES_FSM_REGISTRY_SELECT_DRIVER"),
8659
+ Cell: ({
8660
+ row
8661
+ }) => {
8662
+ return /*#__PURE__*/React.createElement(Dropdown$2, {
8663
+ className: "fsm-registry-dropdown",
8664
+ selected: row.original.driver,
8665
+ option: drivers,
8666
+ select: value => onDriverSelect(row, value),
8667
+ optionKey: "name",
8668
+ t: t
8669
+ });
8670
+ }
8587
8671
  }];
8588
8672
  case "DRIVER":
8589
8673
  return [{
8674
+ Header: t("ES_FSM_REGISTRY_INBOX_USERNAME"),
8675
+ disableSortBy: true,
8676
+ Cell: ({
8677
+ row
8678
+ }) => {
8679
+ var _row$original$owner;
8680
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
8681
+ className: "link"
8682
+ }, /*#__PURE__*/React.createElement(Link, {
8683
+ to: "/digit-ui/employee/vendor/registry/driver-details/" + row.original["id"]
8684
+ }, /*#__PURE__*/React.createElement("div", null, ((_row$original$owner = row.original.owner) === null || _row$original$owner === void 0 ? void 0 : _row$original$owner.userName) || "NA", /*#__PURE__*/React.createElement("br", null)))));
8685
+ }
8686
+ }, {
8590
8687
  Header: t("ES_FSM_REGISTRY_INBOX_DRIVER_NAME"),
8591
8688
  disableSortBy: true,
8592
8689
  accessor: "tripDetails",
@@ -8643,7 +8740,7 @@ const VendorInbox = props => {
8643
8740
  default:
8644
8741
  return [];
8645
8742
  }
8646
- }, [props.selectedTab, vendors]);
8743
+ }, [props.selectedTab, vendors, drivers, tableData, additionalVendorData, t]);
8647
8744
  let result;
8648
8745
  if (props.isLoading) {
8649
8746
  result = /*#__PURE__*/React.createElement(Loader, null);
@@ -9021,6 +9118,15 @@ const SelectServiceType = ({
9021
9118
  value: `${services.name}`
9022
9119
  }));
9023
9120
  setFormattedServiceTypes(transformedData);
9121
+ if (!serviceTypes || serviceTypes.code === "WT") {
9122
+ const defaultWT = transformedData.find(item => item.code === "WT");
9123
+ if (defaultWT) {
9124
+ setserviceTypes(defaultWT);
9125
+ if (userType === "employee") {
9126
+ onSelect(config.key, defaultWT);
9127
+ }
9128
+ }
9129
+ }
9024
9130
  }
9025
9131
  }, [ServiceType]);
9026
9132
  const selectServiceType = value => {
@@ -9227,7 +9333,7 @@ const AddDriver = ({
9227
9333
  additionalDetails: {
9228
9334
  serviceType: additionalDetails
9229
9335
  },
9230
- vendorDriverStatus: "INACTIVE"
9336
+ vendorDriverStatus: "ACTIVE"
9231
9337
  }
9232
9338
  };
9233
9339
  mutate(formData, {
@@ -9383,7 +9489,6 @@ const EditVendorDetails = props => {
9383
9489
  }, {
9384
9490
  enabled: !!dsoId
9385
9491
  });
9386
- console.log(vendorAdditionalData, "w2e3r4t5yh");
9387
9492
  const {
9388
9493
  mutate
9389
9494
  } = Digit.Hooks.fsm.useVendorUpdate(tenantId);
@@ -9984,6 +10089,15 @@ const AddVehicle = ({
9984
10089
  };
9985
10090
  const onFormValueChange = (setValue, formData) => {
9986
10091
  var _formData$vehicle, _formData$vehicle2;
10092
+ if (formData !== null && formData !== void 0 && formData.registrationNumber) {
10093
+ let updatedRegNo = formData.registrationNumber.toUpperCase().replace(/ /g, "-").replace(/[^A-Z0-9-]/g, "");
10094
+ if (updatedRegNo.length > 13) {
10095
+ updatedRegNo = updatedRegNo.slice(0, 13);
10096
+ }
10097
+ if (updatedRegNo !== formData.registrationNumber) {
10098
+ setValue("registrationNumber", updatedRegNo);
10099
+ }
10100
+ }
9987
10101
  if (formData !== null && formData !== void 0 && formData.registrationNumber && formData !== null && formData !== void 0 && formData.ownerName && formData !== null && formData !== void 0 && formData.phone && formData !== null && formData !== void 0 && (_formData$vehicle = formData.vehicle) !== null && _formData$vehicle !== void 0 && _formData$vehicle.modal && formData !== null && formData !== void 0 && (_formData$vehicle2 = formData.vehicle) !== null && _formData$vehicle2 !== void 0 && _formData$vehicle2.type && formData !== null && formData !== void 0 && formData.selectGender) {
9988
10102
  setSubmitValve(true);
9989
10103
  } else {