Skip to content

Commit

Permalink
Merge branch 'develop' into Fix#6372
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafMd-1 authored Oct 14, 2023
2 parents 2590d10 + 5e3012a commit 14380af
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 68 deletions.
20 changes: 12 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"react-google-recaptcha": "^3.1.0",
"react-i18next": "^13.0.1",
"react-markdown": "^8.0.7",
"react-player": "^2.12.0",
"react-player": "^2.13.0",
"react-qr-reader": "^2.2.1",
"react-redux": "^8.1.1",
"react-transition-group": "^4.4.5",
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/Common/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface IConfig {
* Env to toggle peacetime and wartime shifting
*/
wartime_shifting: boolean;
jwt_token_refresh_interval?: number;
}

const useConfig = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/Common/hooks/useMSEplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ export const useMSEMediaPlayer = ({
readPacket(event.data);
}
};
ws.onerror = function (event) {
onError && onError(event);
};
},
false
);
Expand Down
34 changes: 34 additions & 0 deletions src/Components/Assets/AssetFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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();
Expand All @@ -40,6 +48,10 @@ function AssetFilter(props: any) {
);
const [facilityId, setFacilityId] = useState<number | "">(filter.facility);
const [locationId, setLocationId] = useState<string | "">(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(() => {
Expand Down Expand Up @@ -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);
};
Expand All @@ -124,6 +140,13 @@ function AssetFilter(props: any) {
setLocationId(selectedId);
};

const handleDateRangeChange = (event: FieldChangeEvent<DateRange>) => {
const state = { ...warrantyExpiry };
state.after = event.value.start?.toString();
state.before = event.value.end?.toString();
setWarrantyExpiry(state);
};

return (
<FiltersSlideover
advancedFilter={props}
Expand Down Expand Up @@ -203,6 +226,17 @@ function AssetFilter(props: any) {
value={asset_class}
onChange={({ value }) => setAssetClass(value)}
/>

<DateRangeFormField
name="warranty_amc_end_of_validity"
label="Warranty/AMC End of Validity"
value={{
start: getDate(warrantyExpiry.after),
end: getDate(warrantyExpiry.before),
}}
onChange={handleDateRangeChange}
errorClassName="hidden"
/>
</FiltersSlideover>
);
}
Expand Down
24 changes: 14 additions & 10 deletions src/Components/Assets/AssetManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -164,18 +165,18 @@ const AssetManage = (props: AssetManageProps) => {
{transaction.from_location.name}
</span>
</td>
<td className="whitespace-nowrap px-6 py-4 text-left text-sm leading-5 text-gray-500">
<td className="whitespace-nowrap px-6 py-4 text-center text-sm leading-5 text-gray-500">
<span className="font-medium text-gray-900">
{transaction.to_location.name}
</span>
</td>
<td className="whitespace-nowrap px-6 py-4 text-left text-sm leading-5 text-gray-500">
<td className="whitespace-nowrap px-6 py-4 text-center text-sm leading-5 text-gray-500">
<span className="font-medium text-gray-900">
{transaction.performed_by.first_name}{" "}
{transaction.performed_by.last_name}
</span>
</td>
<td className="whitespace-nowrap px-6 py-4 text-left text-sm leading-5 text-gray-500">
<td className="whitespace-nowrap px-6 py-4 text-right text-sm leading-5 text-gray-500">
<span className="font-medium text-gray-900">
{formatDateTime(transaction.modified_date)}
</span>
Expand All @@ -202,7 +203,7 @@ const AssetManage = (props: AssetManageProps) => {
setServiceDetails(
services.map((service: AssetService) => (
<tr key={`service_id_${service.id}`}>
<td className="whitespace-nowrap px-6 py-4 text-center text-sm leading-5 text-gray-500">
<td className="whitespace-nowrap px-6 py-4 text-left text-sm leading-5 text-gray-500">
<span className="font-medium text-gray-900">
{dayjs(service.serviced_on).format("DD MMM YYYY")}
</span>
Expand All @@ -229,7 +230,7 @@ const AssetManage = (props: AssetManageProps) => {
)}
</span>
</td>
<td className="gap-4 whitespace-nowrap px-6 py-4 text-left text-sm leading-5">
<td className="gap-4 whitespace-nowrap px-6 py-4 text-right text-sm leading-5">
<ButtonV2
id="edit-service-history"
authorizeFor={NonReadOnlyUsers}
Expand Down Expand Up @@ -408,6 +409,9 @@ const AssetManage = (props: AssetManageProps) => {
startIcon="l-times"
/>
)}
{warrantyAmcValidityChip(
asset?.warranty_amc_end_of_validity as string
)}
</div>
</div>
<div className="mt-3 hidden text-gray-700 sm:block">
Expand Down Expand Up @@ -525,7 +529,7 @@ const AssetManage = (props: AssetManageProps) => {
<table className="min-w-full divide-y divide-gray-200">
<thead>
<tr>
<th className="bg-gray-50 px-6 py-3 text-center text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
<th className="bg-gray-50 px-6 py-3 text-left text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
Serviced on
</th>
<th className="bg-gray-50 px-6 py-3 text-center text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
Expand All @@ -537,7 +541,7 @@ const AssetManage = (props: AssetManageProps) => {
<th className="bg-gray-50 px-6 py-3 text-center text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
Last Updated
</th>
<th className="bg-gray-50 px-6 py-3 text-center text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
<th className="relative right-10 bg-gray-50 px-6 py-3 text-right text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
Edit
</th>
</tr>
Expand All @@ -558,13 +562,13 @@ const AssetManage = (props: AssetManageProps) => {
<th className="bg-gray-50 px-6 py-3 text-left text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
Moved from
</th>
<th className="bg-gray-50 px-6 py-3 text-left text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
<th className="bg-gray-50 px-6 py-3 text-center text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
Moved to
</th>
<th className="bg-gray-50 px-6 py-3 text-left text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
<th className="bg-gray-50 px-6 py-3 text-center text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
Moved By
</th>
<th className="bg-gray-50 px-6 py-3 text-left text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
<th className="relative right-5 bg-gray-50 px-6 py-3 text-right text-xs font-medium uppercase leading-4 tracking-wider text-gray-500">
Moved On
</th>
</tr>
Expand Down
57 changes: 57 additions & 0 deletions src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
]
);
Expand Down Expand Up @@ -288,6 +294,7 @@ const AssetsList = () => {
) : (
<Chip variant="danger" startIcon="l-cog" text="Not Working" />
)}
{warrantyAmcValidityChip(asset.warranty_amc_end_of_validity)}
</div>
</div>
</Link>
Expand Down Expand Up @@ -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 ?? ""
),
]}
/>
<div className="grow">
Expand Down Expand Up @@ -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 (
<Chip
variant="danger"
startIcon="l-times-circle"
text="AMC/Warranty Expired"
/>
);
} else if (days <= 30) {
return (
<Chip
variant="custom"
className="border-orange-300 bg-orange-100 text-orange-900"
startIcon="l-exclamation-circle"
text="AMC/Warranty Expiring Soon"
/>
);
} else if (days <= 90) {
return (
<Chip
variant="warning"
startIcon="l-exclamation-triangle"
text="AMC/Warranty Expiring Soon"
/>
);
}
};

export default AssetsList;
Loading

0 comments on commit 14380af

Please sign in to comment.