From e8360043344a93d84cea4be5a42bfa6510d9cb41 Mon Sep 17 00:00:00 2001 From: totregex Date: Thu, 19 Dec 2024 18:13:09 +0530 Subject: [PATCH 01/28] refactor all copy functionalities --- src/Utils/utils.ts | 4 +++ src/components/Assets/AssetWarrantyCard.tsx | 29 +++++++++---------- src/components/Licenses/SBOMViewer.tsx | 29 ++++++++++--------- src/components/Shifting/ShiftDetails.tsx | 31 ++++++++------------- 4 files changed, 43 insertions(+), 50 deletions(-) diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index f9e0e14577a..e8240cefad4 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -564,6 +564,10 @@ export function omitBy>( } export const copyToClipboard = async (content: string) => { + if (!content) { + Notification.Error({ msg: "Nothing to copy here!" }); + return; + } try { await navigator.clipboard.writeText(content); Notification.Success({ msg: "Copied to clipboard" }); diff --git a/src/components/Assets/AssetWarrantyCard.tsx b/src/components/Assets/AssetWarrantyCard.tsx index ebaaca7e6c8..542cd05a7f2 100644 --- a/src/components/Assets/AssetWarrantyCard.tsx +++ b/src/components/Assets/AssetWarrantyCard.tsx @@ -1,12 +1,10 @@ -import { t } from "i18next"; import { useEffect, useState } from "react"; -import CopyToClipboard from "react-copy-to-clipboard"; import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon"; import { AssetData } from "@/components/Assets/AssetTypes"; -import { formatDate } from "@/Utils/utils"; +import { copyToClipboard, formatDate } from "@/Utils/utils"; export default function AssetWarrantyCard(props: { asset: AssetData }) { const { asset } = props; @@ -45,19 +43,18 @@ export default function AssetWarrantyCard(props: { asset: AssetData }) {
{details[key as keyof typeof details] || "--"} {key === "Serial Number" && ( - )} diff --git a/src/components/Licenses/SBOMViewer.tsx b/src/components/Licenses/SBOMViewer.tsx index d8a7cdc93df..b26d85cc027 100644 --- a/src/components/Licenses/SBOMViewer.tsx +++ b/src/components/Licenses/SBOMViewer.tsx @@ -1,6 +1,5 @@ import dayjs from "dayjs"; import React, { useState } from "react"; -import { CopyToClipboard } from "react-copy-to-clipboard"; import Card from "@/CAREUI/display/Card"; import CareIcon from "@/CAREUI/icons/CareIcon"; @@ -9,10 +8,13 @@ import beBomData from "@/components/Licenses/be-sbom.json"; import feBomData from "@/components/Licenses/fe-sbom.json"; import licenseUrls from "@/components/Licenses/licenseUrls.json"; +import { copyToClipboard } from "@/Utils/utils"; + const getLicenseUrl = (licenseId: string | undefined): string | null => { if (!licenseId) return null; return licenseUrls[licenseId as keyof typeof licenseUrls] || null; }; + interface CycloneDXExternalRef { url?: string; type?: string; @@ -64,15 +66,10 @@ interface CycloneDXBOM { } const BOMDisplay: React.FC = () => { - const [copyStatus, setCopyStatus] = useState(false); + const [isCopied, setIsCopied] = useState(false); const [showExternalRefs, setShowExternalRefs] = useState(null); const [activeTab, setActiveTab] = useState("bom"); - const handleCopy = () => { - setCopyStatus(true); - setTimeout(() => setCopyStatus(false), 2000); - }; - const bomData = (activeTab === "bom" ? feBomData : beBomData) as CycloneDXBOM; return ( @@ -182,15 +179,17 @@ const BOMDisplay: React.FC = () => { ))}
- { + copyToClipboard(JSON.stringify(bomData, null, 2)); + setIsCopied(true); + setTimeout(() => setIsCopied(false), 2500); + }} > - - - {copyStatus && ( + Copy BOM JSON + + {isCopied && ( Copied to clipboard! diff --git a/src/components/Shifting/ShiftDetails.tsx b/src/components/Shifting/ShiftDetails.tsx index 58685d20fb1..49119e715ed 100644 --- a/src/components/Shifting/ShiftDetails.tsx +++ b/src/components/Shifting/ShiftDetails.tsx @@ -2,7 +2,6 @@ import careConfig from "@careConfig"; import { QRCodeSVG } from "qrcode.react"; import { Link, navigate } from "raviger"; import { useState } from "react"; -import { CopyToClipboard } from "react-copy-to-clipboard"; import { useTranslation } from "react-i18next"; import RecordMeta from "@/CAREUI/display/RecordMeta"; @@ -26,6 +25,7 @@ import { import routes from "@/Utils/request/api"; import useTanStackQueryInstead from "@/Utils/request/useQuery"; +import { copyToClipboard } from "@/Utils/utils"; import { formatDateTime, formatName, formatPatientAge } from "@/Utils/utils"; export default function ShiftDetails(props: { id: string }) { @@ -42,20 +42,17 @@ export default function ShiftDetails(props: { id: string }) { }); const showCopyToclipBoard = (data: any) => { return ( - - setIsCopied(true)} - > - {isCopied ? ( - {t("copied_to_clipboard")} - ) : ( - - - - )} - - + ); }; @@ -93,10 +90,6 @@ export default function ShiftDetails(props: { id: string }) { return formattedText; }; - setTimeout(() => { - setIsCopied(false); - }, 5000); - const showPatientCard = (patientData: PatientModel) => { const patientGender = GENDER_TYPES.find( (i) => i.id === patientData?.gender, From 59b9bfb8a871bd9c9a0df1c3125f3a5902acde61 Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Thu, 19 Dec 2024 18:46:26 +0530 Subject: [PATCH 02/28] Update src/Utils/utils.ts Co-authored-by: Rithvik Nishad --- src/Utils/utils.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts index e8240cefad4..f9e0e14577a 100644 --- a/src/Utils/utils.ts +++ b/src/Utils/utils.ts @@ -564,10 +564,6 @@ export function omitBy>( } export const copyToClipboard = async (content: string) => { - if (!content) { - Notification.Error({ msg: "Nothing to copy here!" }); - return; - } try { await navigator.clipboard.writeText(content); Notification.Success({ msg: "Copied to clipboard" }); From 029b3905ace2647bba763d758df428e7367de78a Mon Sep 17 00:00:00 2001 From: totregex Date: Thu, 19 Dec 2024 22:03:17 +0530 Subject: [PATCH 03/28] create CopyButton component --- src/components/Common/CopyButton.tsx | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/components/Common/CopyButton.tsx diff --git a/src/components/Common/CopyButton.tsx b/src/components/Common/CopyButton.tsx new file mode 100644 index 00000000000..26dc287dddd --- /dev/null +++ b/src/components/Common/CopyButton.tsx @@ -0,0 +1,58 @@ +import { useState } from "react"; + +import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon"; + +import { TooltipComponent, TooltipProvider } from "@/components/ui/tooltip"; + +import { copyToClipboard } from "@/Utils/utils"; + +interface CopyButtonProps { + content: string; + tooltipContent?: string; + btnContent?: string; + resetDuration?: number; + iconClassName?: string; + btnClassName?: string; + icons?: { + copied: IconName; + copy: IconName; + }; +} + +const CopyButton = ({ + content, + tooltipContent = "Copy to clipboard", + btnContent = "", + resetDuration = 2500, + iconClassName = "text-lg", + btnClassName = "", + icons = { copied: "l-check", copy: "l-copy" }, +}: CopyButtonProps) => { + const [isCopied, setIsCopied] = useState(false); + + return ( + + + + + + ); +}; + +export default CopyButton; From 56d858adeb31b00c96c52fbbb88cb77db22da2c8 Mon Sep 17 00:00:00 2001 From: totregex Date: Thu, 19 Dec 2024 22:08:15 +0530 Subject: [PATCH 04/28] use CopyButton component across --- src/components/Assets/AssetWarrantyCard.tsx | 35 +++++---------------- src/components/Licenses/SBOMViewer.tsx | 25 +++++---------- src/components/Shifting/ShiftDetails.tsx | 19 ++++------- src/components/ui/tooltip.tsx | 2 +- 4 files changed, 21 insertions(+), 60 deletions(-) diff --git a/src/components/Assets/AssetWarrantyCard.tsx b/src/components/Assets/AssetWarrantyCard.tsx index 542cd05a7f2..020b9eddca1 100644 --- a/src/components/Assets/AssetWarrantyCard.tsx +++ b/src/components/Assets/AssetWarrantyCard.tsx @@ -1,10 +1,9 @@ -import { useEffect, useState } from "react"; - import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon"; import { AssetData } from "@/components/Assets/AssetTypes"; +import CopyButton from "@/components/Common/CopyButton"; -import { copyToClipboard, formatDate } from "@/Utils/utils"; +import { formatDate } from "@/Utils/utils"; export default function AssetWarrantyCard(props: { asset: AssetData }) { const { asset } = props; @@ -17,17 +16,6 @@ export default function AssetWarrantyCard(props: { asset: AssetData }) { Vendor: asset.vendor_name, }; - const [isCopied, setIsCopied] = useState(false); - - useEffect(() => { - if (isCopied) { - const timeout = setTimeout(() => { - setIsCopied(false); - }, 2000); - return () => clearTimeout(timeout); - } - }, [isCopied]); - return (
@@ -43,20 +31,11 @@ export default function AssetWarrantyCard(props: { asset: AssetData }) {
{details[key as keyof typeof details] || "--"} {key === "Serial Number" && ( - + )}
diff --git a/src/components/Licenses/SBOMViewer.tsx b/src/components/Licenses/SBOMViewer.tsx index b26d85cc027..4e31370a3de 100644 --- a/src/components/Licenses/SBOMViewer.tsx +++ b/src/components/Licenses/SBOMViewer.tsx @@ -4,12 +4,11 @@ import React, { useState } from "react"; import Card from "@/CAREUI/display/Card"; import CareIcon from "@/CAREUI/icons/CareIcon"; +import CopyButton from "@/components/Common/CopyButton"; import beBomData from "@/components/Licenses/be-sbom.json"; import feBomData from "@/components/Licenses/fe-sbom.json"; import licenseUrls from "@/components/Licenses/licenseUrls.json"; -import { copyToClipboard } from "@/Utils/utils"; - const getLicenseUrl = (licenseId: string | undefined): string | null => { if (!licenseId) return null; return licenseUrls[licenseId as keyof typeof licenseUrls] || null; @@ -66,7 +65,6 @@ interface CycloneDXBOM { } const BOMDisplay: React.FC = () => { - const [isCopied, setIsCopied] = useState(false); const [showExternalRefs, setShowExternalRefs] = useState(null); const [activeTab, setActiveTab] = useState("bom"); @@ -179,21 +177,12 @@ const BOMDisplay: React.FC = () => { ))}
- - {isCopied && ( - - Copied to clipboard! - - )} +
diff --git a/src/components/Shifting/ShiftDetails.tsx b/src/components/Shifting/ShiftDetails.tsx index 49119e715ed..e162214bb60 100644 --- a/src/components/Shifting/ShiftDetails.tsx +++ b/src/components/Shifting/ShiftDetails.tsx @@ -11,6 +11,7 @@ import PrintPreview from "@/CAREUI/misc/PrintPreview"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import ButtonV2 from "@/components/Common/ButtonV2"; +import CopyButton from "@/components/Common/CopyButton"; import Loading from "@/components/Common/Loading"; import Page from "@/components/Common/Page"; import { ConsultationModel } from "@/components/Facility/models"; @@ -25,12 +26,10 @@ import { import routes from "@/Utils/request/api"; import useTanStackQueryInstead from "@/Utils/request/useQuery"; -import { copyToClipboard } from "@/Utils/utils"; import { formatDateTime, formatName, formatPatientAge } from "@/Utils/utils"; export default function ShiftDetails(props: { id: string }) { const [isPrintMode, setIsPrintMode] = useState(false); - const [isCopied, setIsCopied] = useState(false); const { t } = useTranslation(); const shiftStatusOptions = careConfig.wartimeShifting @@ -42,17 +41,11 @@ export default function ShiftDetails(props: { id: string }) { }); const showCopyToclipBoard = (data: any) => { return ( - + ); }; diff --git a/src/components/ui/tooltip.tsx b/src/components/ui/tooltip.tsx index 75ca7fdc700..a09466bd0d6 100644 --- a/src/components/ui/tooltip.tsx +++ b/src/components/ui/tooltip.tsx @@ -26,7 +26,7 @@ const TooltipComponent = React.forwardRef< ref={ref} sideOffset={sideOffset} className={cn( - "z-50 overflow-hidden rounded-md bg-gray-900 px-3 py-1.5 text-xs text-gray-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-gray-50 dark:text-gray-900", + "z-50 overflow-hidden rounded-md bg-gray-800 px-3 py-1.5 text-sm text-gray-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-gray-50 dark:text-gray-900", className, )} > From ec05b196553c79bbf53333140d7651ca283357a8 Mon Sep 17 00:00:00 2001 From: totregex Date: Thu, 19 Dec 2024 22:34:52 +0530 Subject: [PATCH 05/28] disable serial copyBtn --- src/components/Assets/AssetWarrantyCard.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/Assets/AssetWarrantyCard.tsx b/src/components/Assets/AssetWarrantyCard.tsx index 020b9eddca1..dbe60dd0d19 100644 --- a/src/components/Assets/AssetWarrantyCard.tsx +++ b/src/components/Assets/AssetWarrantyCard.tsx @@ -30,13 +30,14 @@ export default function AssetWarrantyCard(props: { asset: AssetData }) {
{details[key as keyof typeof details] || "--"} - {key === "Serial Number" && ( - - )} + {key === "Serial Number" && + details[key as keyof typeof details] && ( + + )}
))} From 2c58284ad17b7915b3956e46ad15337b91459413 Mon Sep 17 00:00:00 2001 From: totregex Date: Thu, 19 Dec 2024 22:38:33 +0530 Subject: [PATCH 06/28] revert tooltip class --- src/components/ui/tooltip.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ui/tooltip.tsx b/src/components/ui/tooltip.tsx index a09466bd0d6..75ca7fdc700 100644 --- a/src/components/ui/tooltip.tsx +++ b/src/components/ui/tooltip.tsx @@ -26,7 +26,7 @@ const TooltipComponent = React.forwardRef< ref={ref} sideOffset={sideOffset} className={cn( - "z-50 overflow-hidden rounded-md bg-gray-800 px-3 py-1.5 text-sm text-gray-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-gray-50 dark:text-gray-900", + "z-50 overflow-hidden rounded-md bg-gray-900 px-3 py-1.5 text-xs text-gray-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-gray-50 dark:text-gray-900", className, )} > From 68da53b40fec64b56665e7243e7ca8fb1df685a1 Mon Sep 17 00:00:00 2001 From: totregex Date: Fri, 20 Dec 2024 00:28:43 +0530 Subject: [PATCH 07/28] use cva instead --- src/components/Assets/AssetWarrantyCard.tsx | 1 - src/components/Common/CopyButton.tsx | 43 +++++++++------------ src/components/Licenses/SBOMViewer.tsx | 4 +- src/components/Shifting/ShiftDetails.tsx | 2 +- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/components/Assets/AssetWarrantyCard.tsx b/src/components/Assets/AssetWarrantyCard.tsx index dbe60dd0d19..ed718d40969 100644 --- a/src/components/Assets/AssetWarrantyCard.tsx +++ b/src/components/Assets/AssetWarrantyCard.tsx @@ -35,7 +35,6 @@ export default function AssetWarrantyCard(props: { asset: AssetData }) { )} diff --git a/src/components/Common/CopyButton.tsx b/src/components/Common/CopyButton.tsx index 26dc287dddd..673fbd187f8 100644 --- a/src/components/Common/CopyButton.tsx +++ b/src/components/Common/CopyButton.tsx @@ -1,55 +1,48 @@ +import { VariantProps } from "class-variance-authority"; import { useState } from "react"; +import * as React from "react"; -import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon"; +import CareIcon from "@/CAREUI/icons/CareIcon"; +import { Button, buttonVariants } from "@/components/ui/button"; import { TooltipComponent, TooltipProvider } from "@/components/ui/tooltip"; import { copyToClipboard } from "@/Utils/utils"; -interface CopyButtonProps { +export interface CopyButtonProps + extends React.ButtonHTMLAttributes, + VariantProps { + children?: React.ReactNode; content: string; tooltipContent?: string; - btnContent?: string; - resetDuration?: number; - iconClassName?: string; - btnClassName?: string; - icons?: { - copied: IconName; - copy: IconName; - }; } - const CopyButton = ({ content, tooltipContent = "Copy to clipboard", - btnContent = "", - resetDuration = 2500, - iconClassName = "text-lg", - btnClassName = "", - icons = { copied: "l-check", copy: "l-copy" }, + children, + size, }: CopyButtonProps) => { const [isCopied, setIsCopied] = useState(false); return ( - + ); diff --git a/src/components/Licenses/SBOMViewer.tsx b/src/components/Licenses/SBOMViewer.tsx index 4e31370a3de..900bf20baa4 100644 --- a/src/components/Licenses/SBOMViewer.tsx +++ b/src/components/Licenses/SBOMViewer.tsx @@ -180,8 +180,8 @@ const BOMDisplay: React.FC = () => { diff --git a/src/components/Shifting/ShiftDetails.tsx b/src/components/Shifting/ShiftDetails.tsx index e162214bb60..389381b8be3 100644 --- a/src/components/Shifting/ShiftDetails.tsx +++ b/src/components/Shifting/ShiftDetails.tsx @@ -44,7 +44,7 @@ export default function ShiftDetails(props: { id: string }) { ); }; From ae2426cc53eb3a1cc4d547ea14a66c258c29af42 Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Fri, 20 Dec 2024 08:03:48 +0530 Subject: [PATCH 08/28] Update src/components/Licenses/SBOMViewer.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/components/Licenses/SBOMViewer.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/Licenses/SBOMViewer.tsx b/src/components/Licenses/SBOMViewer.tsx index 900bf20baa4..ea0c070f427 100644 --- a/src/components/Licenses/SBOMViewer.tsx +++ b/src/components/Licenses/SBOMViewer.tsx @@ -178,11 +178,19 @@ const BOMDisplay: React.FC = () => {
{ + try { + return JSON.stringify(bomData, null, 2); + } catch (error) { + console.error('Failed to stringify BOM data:', error); + return ''; + } + })()} tooltipContent="Copy BOM JSON to clipboard" - children="Copy BOM JSON" variant="primary" - /> + > + Copy BOM JSON +
From 4f383e6eccca63e2630736bdff72cff360d96d26 Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Fri, 20 Dec 2024 08:05:13 +0530 Subject: [PATCH 09/28] remove console logs --- src/components/Licenses/SBOMViewer.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Licenses/SBOMViewer.tsx b/src/components/Licenses/SBOMViewer.tsx index ea0c070f427..e4057199349 100644 --- a/src/components/Licenses/SBOMViewer.tsx +++ b/src/components/Licenses/SBOMViewer.tsx @@ -182,7 +182,6 @@ const BOMDisplay: React.FC = () => { try { return JSON.stringify(bomData, null, 2); } catch (error) { - console.error('Failed to stringify BOM data:', error); return ''; } })()} From c14a04d34c4c3e18ed4b8899251f6707b362c703 Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:54:48 +0530 Subject: [PATCH 10/28] drop error handling Co-authored-by: Rithvik Nishad --- src/components/Licenses/SBOMViewer.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/components/Licenses/SBOMViewer.tsx b/src/components/Licenses/SBOMViewer.tsx index e4057199349..e2cd75d372e 100644 --- a/src/components/Licenses/SBOMViewer.tsx +++ b/src/components/Licenses/SBOMViewer.tsx @@ -178,13 +178,7 @@ const BOMDisplay: React.FC = () => {
{ - try { - return JSON.stringify(bomData, null, 2); - } catch (error) { - return ''; - } - })()} + content={JSON.stringify(bomData, null, 2)} tooltipContent="Copy BOM JSON to clipboard" variant="primary" > From 1588cff0f1541d25365ee613c709c8ecd8ab9de8 Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:55:45 +0530 Subject: [PATCH 11/28] Update src/components/Shifting/ShiftDetails.tsx Co-authored-by: Rithvik Nishad --- src/components/Shifting/ShiftDetails.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Shifting/ShiftDetails.tsx b/src/components/Shifting/ShiftDetails.tsx index 389381b8be3..7aa077a7896 100644 --- a/src/components/Shifting/ShiftDetails.tsx +++ b/src/components/Shifting/ShiftDetails.tsx @@ -43,7 +43,6 @@ export default function ShiftDetails(props: { id: string }) { return ( ); From 1ccce49885c51d4b3a0b6d397b22aa441fedc2af Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:56:10 +0530 Subject: [PATCH 12/28] Update src/components/Assets/AssetWarrantyCard.tsx Co-authored-by: Rithvik Nishad --- src/components/Assets/AssetWarrantyCard.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Assets/AssetWarrantyCard.tsx b/src/components/Assets/AssetWarrantyCard.tsx index ed718d40969..93f2a75a533 100644 --- a/src/components/Assets/AssetWarrantyCard.tsx +++ b/src/components/Assets/AssetWarrantyCard.tsx @@ -34,7 +34,6 @@ export default function AssetWarrantyCard(props: { asset: AssetData }) { details[key as keyof typeof details] && ( )}
From ae494c0821b92f54283697161335a5d92baabc1c Mon Sep 17 00:00:00 2001 From: totregex Date: Fri, 20 Dec 2024 13:34:55 +0530 Subject: [PATCH 13/28] fix lint --- src/components/Shifting/ShiftDetails.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/components/Shifting/ShiftDetails.tsx b/src/components/Shifting/ShiftDetails.tsx index 7aa077a7896..df5942a479a 100644 --- a/src/components/Shifting/ShiftDetails.tsx +++ b/src/components/Shifting/ShiftDetails.tsx @@ -40,12 +40,7 @@ export default function ShiftDetails(props: { id: string }) { pathParams: { id: props.id }, }); const showCopyToclipBoard = (data: any) => { - return ( - - ); + return ; }; const copyContent = (data: any) => { From bc9a83117fd0cd340b2cae9b6ea94650cfa3a946 Mon Sep 17 00:00:00 2001 From: totregex Date: Sat, 21 Dec 2024 08:12:43 +0530 Subject: [PATCH 14/28] add CopyButton in DoctorVideoSlideover --- .../Facility/DoctorVideoSlideover.tsx | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/components/Facility/DoctorVideoSlideover.tsx b/src/components/Facility/DoctorVideoSlideover.tsx index 98058fd4bfb..ff3a64a5d7a 100644 --- a/src/components/Facility/DoctorVideoSlideover.tsx +++ b/src/components/Facility/DoctorVideoSlideover.tsx @@ -5,6 +5,7 @@ import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon"; import SlideOver from "@/CAREUI/interactive/SlideOver"; import Switch from "@/CAREUI/interactive/Switch"; +import CopyButton from "@/components/Common/CopyButton"; import Loading from "@/components/Common/Loading"; import { SkillObjectModel } from "@/components/Users/models"; import { UserAssignedModel } from "@/components/Users/models"; @@ -18,7 +19,6 @@ import routes from "@/Utils/request/api"; import useTanStackQueryInstead from "@/Utils/request/useQuery"; import { classNames, - copyToClipboard, formatName, isUserOnline, relativeTime, @@ -241,7 +241,6 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { } const { t } = useTranslation(); - const [copied, setCopied] = useState(false); return (
From 98f484e3979bb3f31e71da01cdfe54d45e1c3cf7 Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Sat, 21 Dec 2024 10:56:10 +0530 Subject: [PATCH 15/28] add disable logic --- src/components/Common/CopyButton.tsx | 1 + src/components/Facility/DoctorVideoSlideover.tsx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Common/CopyButton.tsx b/src/components/Common/CopyButton.tsx index 673fbd187f8..dd4ffaf1fc9 100644 --- a/src/components/Common/CopyButton.tsx +++ b/src/components/Common/CopyButton.tsx @@ -21,6 +21,7 @@ const CopyButton = ({ tooltipContent = "Copy to clipboard", children, size, + disabled = false, }: CopyButtonProps) => { const [isCopied, setIsCopied] = useState(false); diff --git a/src/components/Facility/DoctorVideoSlideover.tsx b/src/components/Facility/DoctorVideoSlideover.tsx index ff3a64a5d7a..eef93afe257 100644 --- a/src/components/Facility/DoctorVideoSlideover.tsx +++ b/src/components/Facility/DoctorVideoSlideover.tsx @@ -295,7 +295,8 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) {
{user.alt_phone_number} From 50edfb94acbba36dd250e099772267e4f03e4ab6 Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Sat, 21 Dec 2024 11:06:42 +0530 Subject: [PATCH 16/28] fix disable logic --- src/components/Common/CopyButton.tsx | 1 - src/components/Facility/DoctorVideoSlideover.tsx | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Common/CopyButton.tsx b/src/components/Common/CopyButton.tsx index dd4ffaf1fc9..673fbd187f8 100644 --- a/src/components/Common/CopyButton.tsx +++ b/src/components/Common/CopyButton.tsx @@ -21,7 +21,6 @@ const CopyButton = ({ tooltipContent = "Copy to clipboard", children, size, - disabled = false, }: CopyButtonProps) => { const [isCopied, setIsCopied] = useState(false); diff --git a/src/components/Facility/DoctorVideoSlideover.tsx b/src/components/Facility/DoctorVideoSlideover.tsx index eef93afe257..5fc009ae693 100644 --- a/src/components/Facility/DoctorVideoSlideover.tsx +++ b/src/components/Facility/DoctorVideoSlideover.tsx @@ -294,11 +294,12 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { )}
+ {user.alt_phone_number && ( + )} {user.alt_phone_number}
From 2c7ab7812e1a7e2b70ba8176f442867dedf07167 Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Sat, 21 Dec 2024 11:09:25 +0530 Subject: [PATCH 17/28] fix lint --- .../Facility/DoctorVideoSlideover.tsx | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/Facility/DoctorVideoSlideover.tsx b/src/components/Facility/DoctorVideoSlideover.tsx index 5fc009ae693..a46813c455c 100644 --- a/src/components/Facility/DoctorVideoSlideover.tsx +++ b/src/components/Facility/DoctorVideoSlideover.tsx @@ -174,7 +174,7 @@ const UserGroupList = (props: { type MSLaunchURI = ( uri: string, successCB?: null | (() => void), - noHandlerCB?: null | (() => void), + noHandlerCB?: null | (() => void) ) => void; function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { @@ -185,7 +185,11 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { e.stopPropagation(); if (!user.alt_phone_number) return; const phoneNumber = user.alt_phone_number?.replace(/\D+/g, ""); - const message = `${courtesyTitle(user)} ${formatName(user)}, I have a query regarding a patient.\n\nPatient Link: ${window.location.href}`; + const message = `${courtesyTitle(user)} ${formatName( + user + )}, I have a query regarding a patient.\n\nPatient Link: ${ + window.location.href + }`; const encodedMessage = encodeURIComponent(message); const whatsappAppURL = `whatsapp://send?phone=${phoneNumber}&text=${encodedMessage}`; const whatsappWebURL = `https://wa.me/${phoneNumber}?text=${encodedMessage}`; @@ -248,7 +252,7 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { "group cursor-default select-none rounded-xl p-3", user.alt_phone_number ? "cursor-pointer border border-secondary-400 transition hover:border-green-500 hover:bg-green-50" - : "pointer-events-none cursor-not-allowed bg-secondary-400", + : "pointer-events-none cursor-not-allowed bg-secondary-400" )} > @@ -294,12 +298,12 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { )}
- {user.alt_phone_number && ( - - )} + {user.alt_phone_number && ( + + )} {user.alt_phone_number}
From d9ed22619e9baffcdf329864fe87643ff3e88640 Mon Sep 17 00:00:00 2001 From: totregex Date: Sat, 21 Dec 2024 11:20:21 +0530 Subject: [PATCH 18/28] format with prettier --- src/components/Facility/DoctorVideoSlideover.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Facility/DoctorVideoSlideover.tsx b/src/components/Facility/DoctorVideoSlideover.tsx index a46813c455c..033e0f992c7 100644 --- a/src/components/Facility/DoctorVideoSlideover.tsx +++ b/src/components/Facility/DoctorVideoSlideover.tsx @@ -174,7 +174,7 @@ const UserGroupList = (props: { type MSLaunchURI = ( uri: string, successCB?: null | (() => void), - noHandlerCB?: null | (() => void) + noHandlerCB?: null | (() => void), ) => void; function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { @@ -186,7 +186,7 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { if (!user.alt_phone_number) return; const phoneNumber = user.alt_phone_number?.replace(/\D+/g, ""); const message = `${courtesyTitle(user)} ${formatName( - user + user, )}, I have a query regarding a patient.\n\nPatient Link: ${ window.location.href }`; @@ -252,7 +252,7 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { "group cursor-default select-none rounded-xl p-3", user.alt_phone_number ? "cursor-pointer border border-secondary-400 transition hover:border-green-500 hover:bg-green-50" - : "pointer-events-none cursor-not-allowed bg-secondary-400" + : "pointer-events-none cursor-not-allowed bg-secondary-400", )} > From f84ba5b4796c00dd3ea6241ef40fc5825597251b Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Sat, 21 Dec 2024 12:12:55 +0530 Subject: [PATCH 19/28] Move content handling logic to CopyButton component --- src/components/Assets/AssetWarrantyCard.tsx | 9 +++------ src/components/Common/CopyButton.tsx | 5 ++++- src/components/Facility/DoctorVideoSlideover.tsx | 10 ++++------ src/components/Licenses/SBOMViewer.tsx | 2 +- src/components/Shifting/ShiftDetails.tsx | 8 ++++---- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/components/Assets/AssetWarrantyCard.tsx b/src/components/Assets/AssetWarrantyCard.tsx index 93f2a75a533..f68c535bd77 100644 --- a/src/components/Assets/AssetWarrantyCard.tsx +++ b/src/components/Assets/AssetWarrantyCard.tsx @@ -30,12 +30,9 @@ export default function AssetWarrantyCard(props: { asset: AssetData }) {
{details[key as keyof typeof details] || "--"} - {key === "Serial Number" && - details[key as keyof typeof details] && ( - - )} + {key === "Serial Number" && ( + + )}
))} diff --git a/src/components/Common/CopyButton.tsx b/src/components/Common/CopyButton.tsx index 673fbd187f8..2f1a675a4b4 100644 --- a/src/components/Common/CopyButton.tsx +++ b/src/components/Common/CopyButton.tsx @@ -13,9 +13,10 @@ export interface CopyButtonProps extends React.ButtonHTMLAttributes, VariantProps { children?: React.ReactNode; - content: string; + content: string | undefined; tooltipContent?: string; } + const CopyButton = ({ content, tooltipContent = "Copy to clipboard", @@ -24,6 +25,8 @@ const CopyButton = ({ }: CopyButtonProps) => { const [isCopied, setIsCopied] = useState(false); + if (content === undefined) return null; + return ( diff --git a/src/components/Facility/DoctorVideoSlideover.tsx b/src/components/Facility/DoctorVideoSlideover.tsx index 033e0f992c7..9df330daba3 100644 --- a/src/components/Facility/DoctorVideoSlideover.tsx +++ b/src/components/Facility/DoctorVideoSlideover.tsx @@ -298,12 +298,10 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { )}
- {user.alt_phone_number && ( - - )} + {user.alt_phone_number}
diff --git a/src/components/Licenses/SBOMViewer.tsx b/src/components/Licenses/SBOMViewer.tsx index e2cd75d372e..e822862007f 100644 --- a/src/components/Licenses/SBOMViewer.tsx +++ b/src/components/Licenses/SBOMViewer.tsx @@ -151,7 +151,7 @@ const BOMDisplay: React.FC = () => { className="block cursor-pointer font-semibold text-primary" onClick={() => setShowExternalRefs( - showExternalRefs === index ? null : index, + showExternalRefs === index ? null : index ) } > diff --git a/src/components/Shifting/ShiftDetails.tsx b/src/components/Shifting/ShiftDetails.tsx index df5942a479a..094d8ac2638 100644 --- a/src/components/Shifting/ShiftDetails.tsx +++ b/src/components/Shifting/ShiftDetails.tsx @@ -79,7 +79,7 @@ export default function ShiftDetails(props: { id: string }) { const showPatientCard = (patientData: PatientModel) => { const patientGender = GENDER_TYPES.find( - (i) => i.id === patientData?.gender, + (i) => i.id === patientData?.gender )?.text; return ( @@ -252,7 +252,7 @@ export default function ShiftDetails(props: { id: string }) { const patientData = data.patient_object; const consultation = data.patient.last_consultation as ConsultationModel; const patientGender = GENDER_TYPES.find( - (i) => i.id === patientData?.gender, + (i) => i.id === patientData?.gender )?.text; return ( @@ -347,7 +347,7 @@ export default function ShiftDetails(props: { id: string }) { {t("date_of_admission")}:{" "} {formatDateTime( - consultation.encounter_date || consultation.created_date, + consultation.encounter_date || consultation.created_date ) || "-"}

@@ -488,7 +488,7 @@ export default function ShiftDetails(props: { id: string }) { Status: {shiftStatusOptions.find( - (option) => data?.status === option.text, + (option) => data?.status === option.text )?.label || data?.status}

From 6c99e4e0a5e69f15094d8c4bddce41b4b00f012a Mon Sep 17 00:00:00 2001 From: totregex Date: Sat, 21 Dec 2024 12:15:49 +0530 Subject: [PATCH 20/28] format with prettier --- src/components/Licenses/SBOMViewer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Licenses/SBOMViewer.tsx b/src/components/Licenses/SBOMViewer.tsx index e822862007f..e2cd75d372e 100644 --- a/src/components/Licenses/SBOMViewer.tsx +++ b/src/components/Licenses/SBOMViewer.tsx @@ -151,7 +151,7 @@ const BOMDisplay: React.FC = () => { className="block cursor-pointer font-semibold text-primary" onClick={() => setShowExternalRefs( - showExternalRefs === index ? null : index + showExternalRefs === index ? null : index, ) } > From 6183a19af8ec0cdded7e0e083cc98e92ab3c30d2 Mon Sep 17 00:00:00 2001 From: totregex Date: Sat, 21 Dec 2024 12:17:25 +0530 Subject: [PATCH 21/28] format ShiftDetails --- src/components/Shifting/ShiftDetails.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Shifting/ShiftDetails.tsx b/src/components/Shifting/ShiftDetails.tsx index 094d8ac2638..df5942a479a 100644 --- a/src/components/Shifting/ShiftDetails.tsx +++ b/src/components/Shifting/ShiftDetails.tsx @@ -79,7 +79,7 @@ export default function ShiftDetails(props: { id: string }) { const showPatientCard = (patientData: PatientModel) => { const patientGender = GENDER_TYPES.find( - (i) => i.id === patientData?.gender + (i) => i.id === patientData?.gender, )?.text; return ( @@ -252,7 +252,7 @@ export default function ShiftDetails(props: { id: string }) { const patientData = data.patient_object; const consultation = data.patient.last_consultation as ConsultationModel; const patientGender = GENDER_TYPES.find( - (i) => i.id === patientData?.gender + (i) => i.id === patientData?.gender, )?.text; return ( @@ -347,7 +347,7 @@ export default function ShiftDetails(props: { id: string }) { {t("date_of_admission")}:{" "} {formatDateTime( - consultation.encounter_date || consultation.created_date + consultation.encounter_date || consultation.created_date, ) || "-"}

@@ -488,7 +488,7 @@ export default function ShiftDetails(props: { id: string }) { Status: {shiftStatusOptions.find( - (option) => data?.status === option.text + (option) => data?.status === option.text, )?.label || data?.status}

From ce9c578604564009ce3a08b008e716662c300a74 Mon Sep 17 00:00:00 2001 From: totregex Date: Sat, 21 Dec 2024 14:45:14 +0530 Subject: [PATCH 22/28] add translations --- public/locale/en.json | 1 + src/components/Common/CopyButton.tsx | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/public/locale/en.json b/public/locale/en.json index b9d5c60539c..3a8bcfacc68 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -551,6 +551,7 @@ "copied_to_clipboard": "Copied to clipboard", "copilot_thinking": "Copilot is thinking...", "copy_phone_number": "Copy Phone Number", + "copy_to_clipboard": "Copy to clipboard", "could_not_autofill": "We could not autofill any fields from what you said", "countries_travelled": "Countries travelled", "covid_19_cat_gov": "Covid_19 Clinical Category as per Govt. of Kerala guideline (A/B/C)", diff --git a/src/components/Common/CopyButton.tsx b/src/components/Common/CopyButton.tsx index 2f1a675a4b4..68547261e4e 100644 --- a/src/components/Common/CopyButton.tsx +++ b/src/components/Common/CopyButton.tsx @@ -1,6 +1,7 @@ import { VariantProps } from "class-variance-authority"; import { useState } from "react"; import * as React from "react"; +import { useTranslation } from "react-i18next"; import CareIcon from "@/CAREUI/icons/CareIcon"; @@ -19,17 +20,20 @@ export interface CopyButtonProps const CopyButton = ({ content, - tooltipContent = "Copy to clipboard", + tooltipContent = t("copy_to_clipboard"), children, size, }: CopyButtonProps) => { const [isCopied, setIsCopied] = useState(false); + const { t } = useTranslation(); if (content === undefined) return null; return ( - +
{details[key as keyof typeof details] || "--"} - {key === "Serial Number" && ( - - )} + {key === "Serial Number" && + details[key as keyof typeof details] && ( + + )}
))} diff --git a/src/components/Facility/DoctorVideoSlideover.tsx b/src/components/Facility/DoctorVideoSlideover.tsx index 9df330daba3..3478b94afb9 100644 --- a/src/components/Facility/DoctorVideoSlideover.tsx +++ b/src/components/Facility/DoctorVideoSlideover.tsx @@ -255,61 +255,59 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) { : "pointer-events-none cursor-not-allowed bg-secondary-400", )} > - -
- { - // Show online icon based on last_login - user.last_login && isUserOnline(user) ? ( - <> - - - - ) : ( - - ) - } +
+ { + // Show online icon based on last_login + user.last_login && isUserOnline(user) ? ( + <> + + + + ) : ( + + ) + } +
+
+
+ + {formatName(user)} + +
-
); } From 9c0a8157efb3854fdb76cecb6d3669db9eb5608c Mon Sep 17 00:00:00 2001 From: Raj kumar <150310085+rajku-dev@users.noreply.github.com> Date: Tue, 24 Dec 2024 09:21:57 +0530 Subject: [PATCH 28/28] Update src/components/Common/CopyButton.tsx Co-authored-by: Rithvik Nishad --- src/components/Common/CopyButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Common/CopyButton.tsx b/src/components/Common/CopyButton.tsx index 16c8e41ac70..b984e31cb28 100644 --- a/src/components/Common/CopyButton.tsx +++ b/src/components/Common/CopyButton.tsx @@ -27,7 +27,7 @@ const CopyButton = ({ const [isCopied, setIsCopied] = useState(false); const { t } = useTranslation(); - if (content === undefined) return null; + if (!content) return null; return (