From e18d241852496bc07445448b42dcca282fe46079 Mon Sep 17 00:00:00 2001 From: Gokulram A Date: Thu, 28 Sep 2023 18:25:16 +0530 Subject: [PATCH 1/2] added warranty filters and labels for assets --- 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 1df9fbde9a6..143ca2add29 100644 --- a/src/Components/Assets/AssetManage.tsx +++ b/src/Components/Assets/AssetManage.tsx @@ -35,6 +35,7 @@ import useAuthUser from "../../Common/hooks/useAuthUser"; import dayjs from "dayjs"; import RelativeDateUserMention from "../Common/RelativeDateUserMention"; import { AssetServiceEditModal } from "./AssetServiceEditModal"; +import { warrantyAmcValidityChip } from "./AssetsList"; interface AssetManageProps { assetId: string; @@ -392,6 +393,9 @@ const AssetManage = (props: AssetManageProps) => { startIcon="l-times" /> )} + {warrantyAmcValidityChip( + asset?.warranty_amc_end_of_validity as string + )} {asset?.description} diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index d91468166ac..b600dbbdc45 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); + + if (warrantyAmcEndDate < today) { + return ( + + ); + } else if ( + warrantyAmcEndDate < new Date(today.setMonth(today.getMonth() + 1)) + ) { + return ( + + ); + } else if ( + warrantyAmcEndDate < new Date(today.setMonth(today.getMonth() + 3)) + ) { + return ( + + ); + } +}; + export default AssetsList; From 4bb691143dee93006f77005e8d9caff003cfc88e Mon Sep 17 00:00:00 2001 From: Gokulram A Date: Fri, 6 Oct 2023 20:08:54 +0530 Subject: [PATCH 2/2] fixed warranty label date --- src/Components/Assets/AssetsList.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index b600dbbdc45..46b4da5283d 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -509,6 +509,10 @@ export const warrantyAmcValidityChip = ( 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 ( - warrantyAmcEndDate < new Date(today.setMonth(today.getMonth() + 1)) - ) { + } else if (days <= 30) { return ( ); - } else if ( - warrantyAmcEndDate < new Date(today.setMonth(today.getMonth() + 3)) - ) { + } else if (days <= 90) { return (