Skip to content

Commit

Permalink
improved asset details page
Browse files Browse the repository at this point in the history
  • Loading branch information
GokulramGHV committed Sep 10, 2023
1 parent fb4e7be commit 603a550
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 41 deletions.
74 changes: 35 additions & 39 deletions src/Components/Assets/AssetManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { UserRole, USER_TYPES } from "../../Common/constants";
import ConfirmDialog from "../Common/ConfirmDialog";
import RecordMeta from "../../CAREUI/display/RecordMeta";
import { useTranslation } from "react-i18next";
const PageTitle = lazy(() => import("../Common/PageTitle"));
const Loading = lazy(() => import("../Common/Loading"));
import * as Notification from "../../Utils/Notifications.js";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
Expand All @@ -35,6 +34,7 @@ import useAuthUser from "../../Common/hooks/useAuthUser";
import dayjs from "dayjs";
import RelativeDateUserMention from "../Common/RelativeDateUserMention";
import { AssetServiceEditModal } from "./AssetServiceEditModal";
import Page from "../Common/components/Page";

interface AssetManageProps {
assetId: string;
Expand Down Expand Up @@ -329,18 +329,28 @@ const AssetManage = (props: AssetManageProps) => {
};

return (
<div className="px-2 pb-2">
<PageTitle
title="Asset Details"
crumbsReplacements={{
[facilityId]: { name: asset?.location_object.facility.name },
assets: { uri: `/assets?facility=${facilityId}` },
[assetId]: {
name: asset?.name,
},
}}
backUrl="/assets"
/>
<Page
title="Asset Details"
crumbsReplacements={{
[facilityId]: { name: asset?.location_object.facility.name },
assets: { uri: `/assets?facility=${facilityId}` },
[assetId]: {
name: asset?.name,
},
}}
backUrl="/assets"
options={
<ButtonV2
onClick={handleDownload}
className="tooltip py-2"
ghost
border
>
<CareIcon className="care-l-export text-lg" />
Export as JSON
</ButtonV2>
}
>
<ConfirmDialog
title="Delete Asset"
description="Are you sure you want to delete this asset?"
Expand All @@ -359,20 +369,19 @@ const AssetManage = (props: AssetManageProps) => {
<span className="break-words text-2xl font-bold md:text-3xl">
{asset?.name}
</span>
<ButtonV2
onClick={handleDownload}
className="tooltip p-4"
variant="secondary"
ghost
circle
>
<CareIcon className="care-l-export text-lg" />
<span className="tooltip-text tooltip-bottom -translate-x-16">
Export as JSON
</span>
</ButtonV2>
<div className="tooltip tooltip-bottom">
<CareIcon
className={`care-l-${assetClassProp.icon} fill-gray-700 text-3xl`}
/>
<span className="tooltip-text">{assetClassProp.name}</span>
</div>
</div>
<div className="flex flex-wrap gap-2">
{asset?.asset_type === "INTERNAL" ? (
<Chip text="Internal" startIcon="l-building" />
) : (
<Chip text="External" startIcon="l-globe" />
)}
{asset?.status === "ACTIVE" ? (
<Chip text="Active" startIcon="l-check" />
) : (
Expand Down Expand Up @@ -402,19 +411,6 @@ const AssetManage = (props: AssetManageProps) => {
icon: "location-pin-alt",
content: asset?.location_object.name,
},
{
label: "Asset Type",
icon: "apps",
content:
asset?.asset_type === "INTERNAL"
? "Internal Asset"
: "External Asset",
},
{
label: "Asset Class",
icon: assetClassProp.icon,
content: assetClassProp.name,
},
{
label: "Asset QR Code ID",
icon: "qrcode-scan",
Expand Down Expand Up @@ -585,7 +581,7 @@ const AssetManage = (props: AssetManageProps) => {
viewOnly={serviceEditData.viewOnly}
/>
)}
</div>
</Page>
);
};

Expand Down
26 changes: 24 additions & 2 deletions src/Components/Assets/AssetWarrantyCard.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import CareIcon from "../../CAREUI/icons/CareIcon";
import { AssetData } from "./AssetTypes";
import { classNames, formatDate } from "../../Utils/utils";
import CopyToClipboard from "react-copy-to-clipboard";
import { t } from "i18next";
import { useState } from "react";

export default function AssetWarrantyCard(props: { asset: AssetData }) {
const { asset } = props;

const details = {
"Serial Number": asset.serial_number,
Expiry:
"Warranty/AMC Expiry":
asset.warranty_amc_end_of_validity &&
formatDate(asset.warranty_amc_end_of_validity),
Vendor: asset.vendor_name,
};

const [isCopied, setIsCopied] = useState(false);

return (
<div className="warranty-card relative z-10 flex h-full w-screen flex-col overflow-hidden p-6 text-white transition-all hover:scale-[1.01] hover:from-primary-600 hover:to-primary-700 md:w-full md:rounded-xl xl:w-96">
<div className="mb-3 text-right text-lg font-bold italic">
Expand All @@ -25,8 +30,25 @@ export default function AssetWarrantyCard(props: { asset: AssetData }) {
<div className="mb-1 text-xs uppercase italic tracking-widest text-gray-200">
{key}
</div>
<div className="font-semibold">
<div className="flex items-center gap-2 font-semibold">
{details[key as keyof typeof details] || "--"}
{key === "Serial Number" && (
<button className="tooltip tooltip-bottom">
<CopyToClipboard
text={details[key as keyof typeof details] || "--"}
onCopy={() => setIsCopied(true)}
>
{isCopied ? (
<span className="text-sm text-white">
{t("copied_to_clipboard")}
</span>
) : (
<CareIcon className="care-l-copy text-lg" />
)}
</CopyToClipboard>
<span className="tooltip-text">Copy to clipboard</span>
</button>
)}
</div>
</div>
))}
Expand Down

0 comments on commit 603a550

Please sign in to comment.