finance-shared 0.0.7 → 0.0.8

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.
@@ -2487,16 +2487,6 @@ instance.use(initReactI18next).init({
2487
2487
  escapeValue: false
2488
2488
  }
2489
2489
  });
2490
- function formatAmount$1(num, showCurrency = true) {
2491
- if (num === null || num === void 0 || typeof num === "string" && isNaN(Number(num))) {
2492
- return showCurrency ? "RM 00.00" : "00.00";
2493
- }
2494
- const formatted = new Intl.NumberFormat("en-US", {
2495
- minimumFractionDigits: 2,
2496
- maximumFractionDigits: 2
2497
- }).format(Number(num));
2498
- return showCurrency ? `RM ${formatted}` : formatted;
2499
- }
2500
2490
  const locale$3 = {
2501
2491
  CHANGE_DETECT_TITLE: "Are you sure want discard changes?",
2502
2492
  CHANGE_DETECT_BUTTON: "Keep Editing",
@@ -16960,7 +16950,7 @@ const CommonTextField = React__default.memo(({
16960
16950
  onBlur: handleBlur,
16961
16951
  inputProps: inputPropsStyle,
16962
16952
  error: !!error,
16963
- helperText: error ? error.message : "",
16953
+ helperText: typeof error === "object" && (error == null ? void 0 : error.message) ? error.message : "",
16964
16954
  ...props
16965
16955
  }
16966
16956
  ) })
@@ -19683,7 +19673,7 @@ const ImageUpload = ({
19683
19673
  var _a2;
19684
19674
  if ((_a2 = e2.target) == null ? void 0 : _a2.result) {
19685
19675
  setImagePreview(e2.target.result.toString());
19686
- onChange(file);
19676
+ onChange == null ? void 0 : onChange(file);
19687
19677
  }
19688
19678
  };
19689
19679
  dispatch(uploadFile(file));
@@ -20165,14 +20155,14 @@ function setLocalStorageItem(key, value) {
20165
20155
  function removeLocalStorageItem(key) {
20166
20156
  localStorage.removeItem(key);
20167
20157
  }
20168
- function formatAmount(num, showCurrency = true) {
20169
- if (typeof num !== "number" || isNaN(num)) {
20158
+ function formatAmount({ num, showCurrency = true }) {
20159
+ if (num === null || num === void 0 || typeof num !== "number" && isNaN(Number(num))) {
20170
20160
  return showCurrency ? "RM 00.00" : "00.00";
20171
20161
  }
20172
20162
  const formatted = new Intl.NumberFormat("en-US", {
20173
20163
  minimumFractionDigits: 2,
20174
20164
  maximumFractionDigits: 2
20175
- }).format(num);
20165
+ }).format(Number(num));
20176
20166
  return showCurrency ? `RM ${formatted}` : formatted;
20177
20167
  }
20178
20168
  const getSectionTitle = (sectionName) => {
@@ -20251,7 +20241,8 @@ const PdfDialog = ({
20251
20241
  ) : /* @__PURE__ */ jsx("img", { src: filePath, alt: "Preview", className: "w-full h-auto" })
20252
20242
  }
20253
20243
  )
20254
- }
20244
+ },
20245
+ filePath
20255
20246
  );
20256
20247
  };
20257
20248
  const PreviewMedia = ({ children, filePath = "", showDefaultView = true }) => {
@@ -24687,10 +24678,10 @@ const initialState = {
24687
24678
  },
24688
24679
  tenantListForDropdownLoading: false
24689
24680
  };
24690
- const getUserList = (roleIds, tenantId, pageIndexParam) => async (dispatch, getState) => {
24681
+ const getUserList = (roleIds, tenantId, pageIndexParam, searchTerm) => async (dispatch, getState) => {
24691
24682
  var _a, _b;
24692
24683
  dispatch(setIsUserListLoading(true));
24693
- const searchUser = getUserSearchKeyword(getState());
24684
+ const searchUser = searchTerm !== void 0 ? searchTerm : getUserSearchKeyword(getState());
24694
24685
  const pagination = getUserListPaginationData(getState());
24695
24686
  const pageIndexToUse = pageIndexParam !== void 0 ? pageIndexParam : pagination.pageIndex;
24696
24687
  try {
@@ -30505,7 +30496,8 @@ const SearchableAutocomplete = memo(
30505
30496
  totalCount: 0
30506
30497
  },
30507
30498
  ref,
30508
- disableClearable = false
30499
+ disableClearable = false,
30500
+ initialSearchTerm = ""
30509
30501
  }) => {
30510
30502
  var _a;
30511
30503
  const [options, setOptions] = useState([]);
@@ -30515,26 +30507,25 @@ const SearchableAutocomplete = memo(
30515
30507
  const [pageIndex, setPageIndex] = useState((pagination == null ? void 0 : pagination.pageIndex) ?? 0);
30516
30508
  const [isFetching, setIsFetching] = useState(false);
30517
30509
  const hasInitialLoadRef = useRef(false);
30510
+ const isInitialFetchingRef = useRef(false);
30518
30511
  const deduplicateOptions = useCallback((existingOptions, newOptions) => {
30519
30512
  const existingIds = new Set(existingOptions == null ? void 0 : existingOptions.map((option) => option.id));
30520
30513
  const filteredNewOptions = newOptions == null ? void 0 : newOptions.filter((option) => !(existingIds == null ? void 0 : existingIds.has(option.id)));
30521
30514
  return [...existingOptions, ...filteredNewOptions];
30522
30515
  }, []);
30523
- const fetchDefaultOptions = useCallback(async () => {
30524
- setLoading2(true);
30525
- try {
30526
- const defaultData = await fetchOptions("", 0);
30527
- setOptions(defaultData);
30528
- } catch (err) {
30529
- console.error("Error fetching default options:", err);
30530
- } finally {
30531
- setLoading2(false);
30532
- }
30533
- }, [fetchOptions]);
30534
30516
  useEffect(() => {
30535
- if (!hasInitialLoadRef.current) {
30517
+ if (!hasInitialLoadRef.current && !isInitialFetchingRef.current) {
30536
30518
  hasInitialLoadRef.current = true;
30537
- fetchDefaultOptions();
30519
+ isInitialFetchingRef.current = true;
30520
+ setLoading2(true);
30521
+ fetchOptions(initialSearchTerm, 0).then((defaultData) => {
30522
+ setOptions(defaultData);
30523
+ }).catch((err) => {
30524
+ console.error("Error fetching default options:", err);
30525
+ }).finally(() => {
30526
+ setLoading2(false);
30527
+ isInitialFetchingRef.current = false;
30528
+ });
30538
30529
  }
30539
30530
  }, []);
30540
30531
  const fetchDebouncedOptions = useCallback(
@@ -30581,7 +30572,7 @@ const SearchableAutocomplete = memo(
30581
30572
  await loadMoreOptions();
30582
30573
  }
30583
30574
  }, [loadMoreOptions]);
30584
- const handleChange = useCallback((selectedValue) => {
30575
+ const handleChange = useCallback(async (selectedValue) => {
30585
30576
  if (selectedValue) {
30586
30577
  const valueToPass = typeof selectedValue === "object" ? selectedValue.id : selectedValue;
30587
30578
  onChange(valueToPass);
@@ -30589,9 +30580,18 @@ const SearchableAutocomplete = memo(
30589
30580
  setSearchTerm("");
30590
30581
  } else {
30591
30582
  onChange(null);
30592
- fetchDefaultOptions();
30583
+ setSearchTerm("");
30584
+ setLoading2(true);
30585
+ try {
30586
+ const defaultData = await fetchOptions("", 0);
30587
+ setOptions(defaultData);
30588
+ } catch (err) {
30589
+ console.error("Error fetching options:", err);
30590
+ } finally {
30591
+ setLoading2(false);
30592
+ }
30593
30593
  }
30594
- }, [onChange, fetchDefaultOptions]);
30594
+ }, [onChange, fetchOptions]);
30595
30595
  const handleInputChange = useCallback((_event, inputValue) => {
30596
30596
  setSearchTerm(inputValue);
30597
30597
  setIsTyping(true);
@@ -30638,19 +30638,13 @@ const MemberAutoComplete = ({
30638
30638
  isTooltipShow = true,
30639
30639
  variant = "filled",
30640
30640
  dataTestId = "",
30641
- tenantId
30641
+ tenantId,
30642
+ initialSearchTerm = ""
30642
30643
  }) => {
30643
30644
  const dispatch = useDispatch();
30644
30645
  const loading = useSelector(getIsUserListLoading);
30645
30646
  const pagination = useSelector(getUserListPaginationData);
30646
30647
  const [hasMoreData, setHasMoreData] = useState(true);
30647
- const onChangeRef = useRef(onChange);
30648
- const roleIdsRef = useRef(roleIds);
30649
- const previousSearchTermRef = useRef("");
30650
- useEffect(() => {
30651
- onChangeRef.current = onChange;
30652
- roleIdsRef.current = roleIds;
30653
- }, [onChange, roleIds]);
30654
30648
  useEffect(() => {
30655
30649
  return () => {
30656
30650
  dispatch(setUserSearchKeyword(""));
@@ -30658,21 +30652,17 @@ const MemberAutoComplete = ({
30658
30652
  setHasMoreData(true);
30659
30653
  };
30660
30654
  }, [dispatch]);
30661
- const handleOptionChange = useCallback((value2) => {
30662
- onChangeRef.current(value2);
30655
+ const handleOptionChange = (value2) => {
30656
+ onChange(value2);
30663
30657
  dispatch(setIsUserListLoading(false));
30664
- }, [dispatch]);
30665
- const fetchUserOptions = useCallback(async (searchTerm, pageIndex) => {
30666
- if (previousSearchTermRef.current !== searchTerm) {
30667
- previousSearchTermRef.current = searchTerm;
30668
- setHasMoreData(true);
30669
- }
30658
+ };
30659
+ const fetchUserOptions = async (searchTerm, pageIndex) => {
30670
30660
  if (pageIndex > 0 && !hasMoreData) {
30671
30661
  return [];
30672
30662
  }
30673
30663
  dispatch(setUserSearchKeyword(searchTerm));
30674
30664
  dispatch(setUserListPagination({ pageIndex }));
30675
- const newOptions = await dispatch(getUserList(roleIdsRef.current, tenantId, pageIndex));
30665
+ const newOptions = await dispatch(getUserList(roleIds, tenantId, pageIndex, searchTerm));
30676
30666
  if (!newOptions || Array.isArray(newOptions) && newOptions.length === 0) {
30677
30667
  setHasMoreData(false);
30678
30668
  if (pageIndex > 0) {
@@ -30686,7 +30676,7 @@ const MemberAutoComplete = ({
30686
30676
  label: ((_a = item == null ? void 0 : item.additionalDetails) == null ? void 0 : _a.nationalId) ? `${item.userName} (${(_b = item == null ? void 0 : item.additionalDetails) == null ? void 0 : _b.nationalId})` : item.userName
30687
30677
  };
30688
30678
  })) || [];
30689
- }, [dispatch, tenantId, hasMoreData]);
30679
+ };
30690
30680
  return /* @__PURE__ */ jsx(
30691
30681
  SearchableAutocomplete,
30692
30682
  {
@@ -30701,7 +30691,8 @@ const MemberAutoComplete = ({
30701
30691
  required,
30702
30692
  pagination,
30703
30693
  style,
30704
- isTooltipShow
30694
+ isTooltipShow,
30695
+ initialSearchTerm
30705
30696
  }
30706
30697
  );
30707
30698
  };
@@ -30728,7 +30719,8 @@ function RemarksDialog({
30728
30719
  ReassignStaffFormComponent,
30729
30720
  staffRoleIds = [],
30730
30721
  dataTestId = "",
30731
- themesConfig = {}
30722
+ themesConfig = {},
30723
+ remarksCount = 0
30732
30724
  }) {
30733
30725
  const {
30734
30726
  canViewRemarks = true,
@@ -30739,23 +30731,46 @@ function RemarksDialog({
30739
30731
  const { t: t2 } = useTranslation("Dialog");
30740
30732
  const dispatch = useDispatch();
30741
30733
  const sectionTitle = getSectionTitle(sectionName);
30742
- const remarksList = useSelector(getRemarkListData);
30743
- const isFormLoading = useSelector(getIsAddRemarkFormLoading);
30734
+ const [open, setOpen] = useState(false);
30735
+ const [hasOpened, setHasOpened] = useState(false);
30736
+ const [localPendingCount, setLocalPendingCount] = useState(null);
30744
30737
  const [popoverState, setPopoverState] = useState({
30745
30738
  anchorEl: null,
30746
30739
  remarkId: null,
30747
30740
  remarkDetails: null
30748
30741
  });
30749
- const [open, setOpen] = useState(false);
30750
- const [countOfFalseActions, setCountOfFalseActions] = useState(0);
30742
+ const remarksList = useSelector(getRemarkListData);
30743
+ const isFormLoading = useSelector(getIsAddRemarkFormLoading);
30744
+ const pendingRemarksCount = remarksList.filter(
30745
+ (remark) => !remark.hasActionTaken && remark.sectionName === sectionName
30746
+ ).length;
30747
+ const isSectionDataLoaded = !!remarksList.find(
30748
+ (remark) => remark.sectionName === sectionName
30749
+ );
30750
+ useEffect(() => {
30751
+ if (isSectionDataLoaded) {
30752
+ setLocalPendingCount(pendingRemarksCount);
30753
+ }
30754
+ }, [isSectionDataLoaded, pendingRemarksCount]);
30755
+ useEffect(() => {
30756
+ if (!open) {
30757
+ setHasOpened(false);
30758
+ }
30759
+ }, [open]);
30760
+ const getDisplayCount = () => {
30761
+ if (localPendingCount !== null) {
30762
+ return localPendingCount;
30763
+ }
30764
+ if (hasOpened || isSectionDataLoaded) {
30765
+ return pendingRemarksCount;
30766
+ }
30767
+ return remarksCount;
30768
+ };
30769
+ const displayCount = getDisplayCount();
30751
30770
  const schema = create$3().shape({
30752
30771
  remark: create$6().required(t2("REMARK_IS_REQUIRED")),
30753
30772
  remarkType: create$6().required(t2("REMARK_TYPE_IS_REQUIRED")),
30754
- assignedToUserId: create$6().when("remarkType", {
30755
- is: "Internal",
30756
- then: (schema2) => schema2.required(t2("INTERNAL_OPTION_IS_REQUIRED")),
30757
- otherwise: (schema2) => schema2.notRequired()
30758
- })
30773
+ assignedToUserId: create$6().notRequired()
30759
30774
  });
30760
30775
  const { control, formState, handleSubmit, reset } = useForm({
30761
30776
  mode: "onChange",
@@ -30775,14 +30790,6 @@ function RemarksDialog({
30775
30790
  }));
30776
30791
  }
30777
30792
  }, [open, financeApplicationId, sectionName, dispatch]);
30778
- useEffect(() => {
30779
- if (remarksList) {
30780
- const count = remarksList.filter(
30781
- (item) => item.sectionName === sectionName && !item.hasActionTaken
30782
- ).length;
30783
- setCountOfFalseActions(count);
30784
- }
30785
- }, [remarksList, sectionName]);
30786
30793
  const handleToggleRemark = (index) => {
30787
30794
  const remark = remarksList[index];
30788
30795
  const updatedRemark = { ...remark, hasActionTaken: !remark.hasActionTaken };
@@ -30790,6 +30797,7 @@ function RemarksDialog({
30790
30797
  };
30791
30798
  const handleOpen = () => {
30792
30799
  setOpen(true);
30800
+ setHasOpened(true);
30793
30801
  };
30794
30802
  const handleClose = () => {
30795
30803
  setOpen(false);
@@ -30837,7 +30845,7 @@ function RemarksDialog({
30837
30845
  }
30838
30846
  } : {};
30839
30847
  return /* @__PURE__ */ jsxs(Fragment, { children: [
30840
- /* @__PURE__ */ jsx(Badge, { badgeContent: countOfFalseActions, color: "error", children: /* @__PURE__ */ jsx(
30848
+ /* @__PURE__ */ jsx(Badge, { badgeContent: displayCount, color: "error", children: /* @__PURE__ */ jsx(
30841
30849
  Button$1,
30842
30850
  {
30843
30851
  "data-test-id": dataTestId,
@@ -31025,7 +31033,7 @@ function RemarksDialog({
31025
31033
  roleIds: staffRoleIds,
31026
31034
  tenantId,
31027
31035
  onChange: (value) => field.onChange(value || ""),
31028
- required: true,
31036
+ required: false,
31029
31037
  value: field.value || "",
31030
31038
  error: errors2.assignedToUserId ? errors2.assignedToUserId.message : void 0
31031
31039
  }
@@ -31095,8 +31103,10 @@ const CommonStatusChangeDialog = ({
31095
31103
  defaultValues,
31096
31104
  resolver: o(schema)
31097
31105
  });
31098
- const { control, formState, handleSubmit, setValue } = methods;
31106
+ const { control, formState, handleSubmit, setValue, watch } = methods;
31099
31107
  const { isValid: isValid2 } = formState;
31108
+ const currentStatus = watch("status");
31109
+ const isStatusChanged = currentStatus === existingStatus;
31100
31110
  useEffect(() => {
31101
31111
  if (existingStatus) {
31102
31112
  setValue("status", existingStatus);
@@ -31161,7 +31171,7 @@ const CommonStatusChangeDialog = ({
31161
31171
  SaveButton,
31162
31172
  {
31163
31173
  variant: "contained",
31164
- disabled: !isValid2 || isLoading,
31174
+ disabled: !isValid2 || isLoading || isStatusChanged,
31165
31175
  isLoading,
31166
31176
  text: t2("SUBMIT")
31167
31177
  }
@@ -44350,6 +44360,7 @@ const FinanceApplicationAutocomplete = ({
44350
44360
  const TenantAutocomplete = ({
44351
44361
  value,
44352
44362
  onChange,
44363
+ label = "TENANT",
44353
44364
  error,
44354
44365
  required = false,
44355
44366
  status = "",
@@ -44404,7 +44415,7 @@ const TenantAutocomplete = ({
44404
44415
  return /* @__PURE__ */ jsx(
44405
44416
  SearchableAutocomplete,
44406
44417
  {
44407
- label: t2("TENANT"),
44418
+ label: t2(label),
44408
44419
  value,
44409
44420
  onChange: (selectedValue) => handleChange(selectedValue, false),
44410
44421
  fetchOptions: (searchTerm, pageIndex) => fetchTenantOptions(searchTerm, pageIndex),
@@ -60207,7 +60218,6 @@ export {
60207
60218
  DigitalProcessSignature,
60208
60219
  DocumentSigningDialog,
60209
60220
  FinanceApplicationAutocomplete,
60210
- formatAmount$1 as FormatAmount,
60211
60221
  FuseMessage$1 as FuseMessage,
60212
60222
  ImageUpload,
60213
60223
  InfoDialog,