From 0866331fcd6564ad12b0ab091bd8b426fdfe502d Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh <63492939+thedevildude@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:10:34 +0530 Subject: [PATCH 1/5] Replaced date-fns utility functions from DateInputV2 component with day.js (#6405) * resolved conflict * replaced getDay, getDaysInMonth, isEqual with dayjs utils --- src/Components/Common/DateInputV2.tsx | 63 ++++++++++++--------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/src/Components/Common/DateInputV2.tsx b/src/Components/Common/DateInputV2.tsx index 12009cb495f..95652e68638 100644 --- a/src/Components/Common/DateInputV2.tsx +++ b/src/Components/Common/DateInputV2.tsx @@ -1,14 +1,4 @@ import { MutableRefObject, useEffect, useState } from "react"; -import { - addMonths, - addYears, - format, - getDay, - getDaysInMonth, - isEqual, - subMonths, - subYears, -} from "date-fns"; import CareIcon from "../../CAREUI/icons/CareIcon"; import { Popover } from "@headlessui/react"; @@ -64,14 +54,20 @@ const DateInputV2: React.FC = ({ const decrement = () => { switch (type) { case "date": - setDatePickerHeaderDate((prev) => subMonths(prev, 1)); + setDatePickerHeaderDate((prev) => + dayjs(prev).subtract(1, "month").toDate() + ); break; case "month": - setDatePickerHeaderDate((prev) => subYears(prev, 1)); + setDatePickerHeaderDate((prev) => + dayjs(prev).subtract(1, "year").toDate() + ); break; case "year": - setDatePickerHeaderDate((prev) => subYears(prev, 1)); - setYear((prev) => subYears(prev, 10)); + setDatePickerHeaderDate((prev) => + dayjs(prev).subtract(1, "year").toDate() + ); + setYear((prev) => dayjs(prev).subtract(10, "year").toDate()); break; } }; @@ -79,24 +75,24 @@ const DateInputV2: React.FC = ({ const increment = () => { switch (type) { case "date": - setDatePickerHeaderDate((prev) => addMonths(prev, 1)); + setDatePickerHeaderDate((prev) => dayjs(prev).add(1, "month").toDate()); break; case "month": - setDatePickerHeaderDate((prev) => addYears(prev, 1)); + setDatePickerHeaderDate((prev) => dayjs(prev).add(1, "year").toDate()); break; case "year": - setDatePickerHeaderDate((prev) => addYears(prev, 1)); - setYear((prev) => addYears(prev, 10)); + setDatePickerHeaderDate((prev) => dayjs(prev).add(1, "year").toDate()); + setYear((prev) => dayjs(prev).add(10, "year").toDate()); break; } }; const isSelectedDate = (date: number) => { - if (value) - return isEqual( - new Date(value.getFullYear(), value.getMonth(), date), - value - ); + if (value) { + return dayjs( + new Date(value.getFullYear(), value.getMonth(), date) + ).isSame(dayjs(value)); + } }; type CloseFunction = ( @@ -117,9 +113,11 @@ const DateInputV2: React.FC = ({ }; const getDayCount = (date: Date) => { - const daysInMonth = getDaysInMonth(date); + const daysInMonth = dayjs(date).daysInMonth(); - const dayOfWeek = getDay(new Date(date.getFullYear(), date.getMonth(), 1)); + const dayOfWeek = dayjs( + new Date(date.getFullYear(), date.getMonth(), 1) + ).day(); const blankDaysArray = []; for (let i = 1; i <= dayOfWeek; i++) { blankDaysArray.push(i); @@ -282,7 +280,7 @@ const DateInputV2: React.FC = ({ onClick={showMonthPicker} className="cursor-pointer rounded px-3 py-1 text-center font-medium text-black hover:bg-gray-300" > - {format(datePickerHeaderDate, "MMMM")} + {dayjs(datePickerHeaderDate).format("MMMM")} )}
= ({

{type == "year" ? year.getFullYear() - : format(datePickerHeaderDate, "yyyy")} + : dayjs(datePickerHeaderDate).format("YYYY")}

@@ -371,14 +369,9 @@ const DateInputV2: React.FC = ({ )} onClick={setMonthValue(i)} > - {format( - new Date( - datePickerHeaderDate.getFullYear(), - i, - 1 - ), - "MMM" - )} + {dayjs( + new Date(datePickerHeaderDate.getFullYear(), i, 1) + ).format("MMM")} ))} From 17515b86dcec3758b00beacf0edf7e2e9c3dc689 Mon Sep 17 00:00:00 2001 From: Gokulram A Date: Mon, 9 Oct 2023 16:11:02 +0530 Subject: [PATCH 2/5] Aligned Service History & Transaction History in Asset Details (#6382) * Aligned Service History & Transaction History in Asset Details * aliged moved on and edit properly --- src/Components/Assets/AssetManage.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Components/Assets/AssetManage.tsx b/src/Components/Assets/AssetManage.tsx index 84325d704aa..17078583681 100644 --- a/src/Components/Assets/AssetManage.tsx +++ b/src/Components/Assets/AssetManage.tsx @@ -164,18 +164,18 @@ const AssetManage = (props: AssetManageProps) => { {transaction.from_location.name} - + {transaction.to_location.name} - + {transaction.performed_by.first_name}{" "} {transaction.performed_by.last_name} - + {formatDateTime(transaction.modified_date)} @@ -202,7 +202,7 @@ const AssetManage = (props: AssetManageProps) => { setServiceDetails( services.map((service: AssetService) => ( - + {dayjs(service.serviced_on).format("DD MMM YYYY")} @@ -229,7 +229,7 @@ const AssetManage = (props: AssetManageProps) => { )} - + { - - @@ -558,13 +558,13 @@ const AssetManage = (props: AssetManageProps) => { - - - From 10179d3c286ba2288bb1cc934b7e2ecf4d017f70 Mon Sep 17 00:00:00 2001 From: Gokulram A Date: Mon, 9 Oct 2023 16:12:50 +0530 Subject: [PATCH 3/5] Added AMC Warranty filters and expiry labels for assets (#6364) * added warranty filters and labels for assets * fixed warranty label date --- src/Components/Assets/AssetFilter.tsx | 34 ++++++++++++++++ src/Components/Assets/AssetManage.tsx | 4 ++ src/Components/Assets/AssetsList.tsx | 57 +++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/src/Components/Assets/AssetFilter.tsx b/src/Components/Assets/AssetFilter.tsx index 4fc4ff6d7f2..4dca7dfecdb 100644 --- a/src/Components/Assets/AssetFilter.tsx +++ b/src/Components/Assets/AssetFilter.tsx @@ -14,6 +14,11 @@ import { AssetClass, AssetLocationObject } from "./AssetTypes"; import { FieldLabel } from "../Form/FormFields/FormField"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; +import DateRangeFormField from "../Form/FormFields/DateRangeFormField"; +import dayjs from "dayjs"; +import { FieldChangeEvent } from "../Form/FormFields/Utils"; +import { DateRange } from "../Common/DateRangeInputV2"; +import { dateQueryString } from "../../Utils/utils"; const initialLocation = { id: "", @@ -25,6 +30,9 @@ const initialLocation = { }, }; +const getDate = (value: any) => + value && dayjs(value).isValid() && dayjs(value).toDate(); + function AssetFilter(props: any) { const { filter, onChange, closeFilter } = props; const dispatch: any = useDispatch(); @@ -40,6 +48,10 @@ function AssetFilter(props: any) { ); const [facilityId, setFacilityId] = useState(filter.facility); const [locationId, setLocationId] = useState(filter.location); + const [warrantyExpiry, setWarrantyExpiry] = useState({ + before: filter.warranty_amc_end_of_validity_before || null, + after: filter.warranty_amc_end_of_validity_after || null, + }); const [qParams, _] = useQueryParams(); useEffect(() => { @@ -112,6 +124,10 @@ function AssetFilter(props: any) { asset_class: asset_class ?? "", status: asset_status ?? "", location: locationId, + warranty_amc_end_of_validity_before: dateQueryString( + warrantyExpiry.before + ), + warranty_amc_end_of_validity_after: dateQueryString(warrantyExpiry.after), }; onChange(data); }; @@ -124,6 +140,13 @@ function AssetFilter(props: any) { setLocationId(selectedId); }; + const handleDateRangeChange = (event: FieldChangeEvent) => { + const state = { ...warrantyExpiry }; + state.after = event.value.start?.toString(); + state.before = event.value.end?.toString(); + setWarrantyExpiry(state); + }; + return ( setAssetClass(value)} /> + + ); } diff --git a/src/Components/Assets/AssetManage.tsx b/src/Components/Assets/AssetManage.tsx index 17078583681..e6d1836e27b 100644 --- a/src/Components/Assets/AssetManage.tsx +++ b/src/Components/Assets/AssetManage.tsx @@ -34,6 +34,7 @@ import useAuthUser from "../../Common/hooks/useAuthUser"; import dayjs from "dayjs"; import RelativeDateUserMention from "../Common/RelativeDateUserMention"; import { AssetServiceEditModal } from "./AssetServiceEditModal"; +import { warrantyAmcValidityChip } from "./AssetsList"; import Page from "../Common/components/Page"; interface AssetManageProps { @@ -408,6 +409,9 @@ const AssetManage = (props: AssetManageProps) => { startIcon="l-times" /> )} + {warrantyAmcValidityChip( + asset?.warranty_amc_end_of_validity as string + )}
diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index d91468166ac..46b4da5283d 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -74,6 +74,10 @@ const AssetsList = () => { asset_class: qParams.asset_class || "", location: qParams.facility ? qParams.location || "" : "", status: qParams.status || "", + warranty_amc_end_of_validity_before: + qParams.warranty_amc_end_of_validity_before || "", + warranty_amc_end_of_validity_after: + qParams.warranty_amc_end_of_validity_after || "", }; const { data } = await dispatch(listAssets(params)); if (!status.aborted) { @@ -103,6 +107,8 @@ const AssetsList = () => { qParams.asset_class, qParams.location, qParams.status, + qParams.warranty_amc_end_of_validity_before, + qParams.warranty_amc_end_of_validity_after, dispatch, ] ); @@ -288,6 +294,7 @@ const AssetsList = () => { ) : ( )} + {warrantyAmcValidityChip(asset.warranty_amc_end_of_validity)}
@@ -428,6 +435,16 @@ const AssetsList = () => { value("Asset Class", "asset_class", asset_class ?? ""), value("Status", "status", status?.replace(/_/g, " ") ?? ""), value("Location", "location", locationName ?? ""), + value( + "Warranty AMC End Of Validity Before", + "warranty_amc_end_of_validity_before", + qParams.warranty_amc_end_of_validity_before ?? "" + ), + value( + "Warranty AMC End Of Validity After", + "warranty_amc_end_of_validity_after", + qParams.warranty_amc_end_of_validity_after ?? "" + ), ]} />
@@ -484,4 +501,44 @@ const AssetsList = () => { ); }; +export const warrantyAmcValidityChip = ( + warranty_amc_end_of_validity: string +) => { + if (warranty_amc_end_of_validity === "" || !warranty_amc_end_of_validity) + return; + const today = new Date(); + const warrantyAmcEndDate = new Date(warranty_amc_end_of_validity); + + const days = Math.ceil( + Math.abs(Number(warrantyAmcEndDate) - Number(today)) / (1000 * 60 * 60 * 24) + ); + + if (warrantyAmcEndDate < today) { + return ( + + ); + } else if (days <= 30) { + return ( + + ); + } else if (days <= 90) { + return ( + + ); + } +}; + export default AssetsList; From a21bc89dacf1d914b44295b62fa9fa078c4d89bb Mon Sep 17 00:00:00 2001 From: Kshitij Verma <101321276+kshitijv256@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:13:32 +0530 Subject: [PATCH 4/5] whitelisted jwt_token_refresh_interval (#6418) * whitelisted jwt_token_refresh_interval * removed todo --- public/config.json | 3 ++- src/Common/hooks/useConfig.ts | 1 + src/Providers/AuthUserProvider.tsx | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/public/config.json b/public/config.json index 8bb0dab3b57..5e67902d4fe 100644 --- a/public/config.json +++ b/public/config.json @@ -22,5 +22,6 @@ "kasp_full_string": "Karunya Arogya Suraksha Padhathi", "sample_format_asset_import": "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=11JaEhNHdyCHth4YQs_44YaRlP77Rrqe81VSEfg1glko&exportFormat=xlsx", "sample_format_external_result_import": "https://docs.google.com/spreadsheets/d/17VfgryA6OYSYgtQZeXU9mp7kNvLySeEawvnLBO_1nuE/export?format=csv&id=17VfgryA6OYSYgtQZeXU9mp7kNvLySeEawvnLBO_1nuE", - "enable_abdm": true + "enable_abdm": true, + "jwt_token_refresh_interval": 300000 } \ No newline at end of file diff --git a/src/Common/hooks/useConfig.ts b/src/Common/hooks/useConfig.ts index 7b956afec07..15e456ea571 100644 --- a/src/Common/hooks/useConfig.ts +++ b/src/Common/hooks/useConfig.ts @@ -68,6 +68,7 @@ export interface IConfig { * Env to toggle peacetime and wartime shifting */ wartime_shifting: boolean; + jwt_token_refresh_interval?: number; } const useConfig = () => { diff --git a/src/Providers/AuthUserProvider.tsx b/src/Providers/AuthUserProvider.tsx index 64027a17215..a64b38f630c 100644 --- a/src/Providers/AuthUserProvider.tsx +++ b/src/Providers/AuthUserProvider.tsx @@ -5,6 +5,7 @@ import routes from "../Redux/api"; import useQuery from "../Utils/request/useQuery"; import { LocalStorageKeys } from "../Common/constants"; import request from "../Utils/request/request"; +import useConfig from "../Common/hooks/useConfig"; interface Props { children: React.ReactNode; @@ -12,6 +13,7 @@ interface Props { } export default function AuthUserProvider({ children, unauthorized }: Props) { + const { jwt_token_refresh_interval } = useConfig(); const { res, data, loading } = useQuery(routes.currentUser, { refetchOnWindowFocus: false, prefetch: true, @@ -24,8 +26,11 @@ export default function AuthUserProvider({ children, unauthorized }: Props) { } updateRefreshToken(true); - setInterval(() => updateRefreshToken(), 5 * 60 * 1000); // TODO: move this interval to config.json - }, [data]); + setInterval( + () => updateRefreshToken(), + jwt_token_refresh_interval ?? 5 * 60 * 3000 + ); + }, [data, jwt_token_refresh_interval]); if (loading || !res) { return ; From 59daace7ce8e2d2131e13241d906d955f2aad0a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:19:36 +0530 Subject: [PATCH 5/5] Bump uuid from 9.0.0 to 9.0.1 (#6409) Bumps [uuid](https://github.com/uuidjs/uuid) from 9.0.0 to 9.0.1. - [Changelog](https://github.com/uuidjs/uuid/blob/main/CHANGELOG.md) - [Commits](https://github.com/uuidjs/uuid/compare/v9.0.0...v9.0.1) --- updated-dependencies: - dependency-name: uuid dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 12 ++++++++---- package.json | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 54ef3890c77..1fcda2c19ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -57,7 +57,7 @@ "rehype-raw": "^6.1.1", "rescript-webapi": "^0.8.0", "use-keyboard-shortcut": "^1.1.6", - "uuid": "^9.0.0" + "uuid": "^9.0.1" }, "devDependencies": { "@storybook/addon-essentials": "^7.0.26", @@ -21083,9 +21083,13 @@ } }, "node_modules/uuid": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", - "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } diff --git a/package.json b/package.json index 246734dc3d4..c9a9e80258c 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "rehype-raw": "^6.1.1", "rescript-webapi": "^0.8.0", "use-keyboard-shortcut": "^1.1.6", - "uuid": "^9.0.0" + "uuid": "^9.0.1" }, "devDependencies": { "@storybook/addon-essentials": "^7.0.26",
+ Serviced on @@ -537,7 +537,7 @@ const AssetManage = (props: AssetManageProps) => { Last Updated + Edit
Moved from + Moved to + Moved By + Moved On