Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 'copyToClipboard' utility function #9449

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@
"contribute_github": "Contribute on Github",
"copied_to_clipboard": "Copied to clipboard",
"copilot_thinking": "Copilot is thinking...",
"copy_phone_number": "Copy Phone Number",
"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)",
Expand Down
10 changes: 10 additions & 0 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PatientModel } from "@/components/Patient/models";
import { AREACODES, IN_LANDLINE_AREA_CODES } from "@/common/constants";
import phoneCodesJson from "@/common/static/countryPhoneAndFlags.json";

import * as Notification from "@/Utils/Notifications";
import dayjs from "@/Utils/dayjs";

interface ApacheParams {
Expand Down Expand Up @@ -561,3 +562,12 @@ export function omitBy<T extends Record<string, unknown>>(
Object.entries(obj).filter(([_, value]) => !predicate(value)),
) as Partial<T>;
}

export const copyToClipboard = async (content: string) => {
try {
await navigator.clipboard.writeText(content);
Notification.Success({ msg: "Copied to clipboard" });
} catch (err) {
Notification.Error({ msg: "Copying is not allowed" });
}
};
Jacobjeevan marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 16 additions & 7 deletions src/components/Facility/DoctorVideoSlideover.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from "react";
import { useState } from "react";
import { useTranslation } from "react-i18next";

import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon";
import SlideOver from "@/CAREUI/interactive/SlideOver";
Expand All @@ -17,6 +18,7 @@ import routes from "@/Utils/request/api";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import {
classNames,
copyToClipboard,
formatName,
isUserOnline,
relativeTime,
Expand Down Expand Up @@ -238,6 +240,9 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) {
}
}

const { t } = useTranslation();
const [copied, setCopied] = useState(false);

return (
<div
className={classNames(
Expand Down Expand Up @@ -293,18 +298,22 @@ function UserListItem({ user }: { user: UserAnnotatedWithGroup }) {
<a
role="button"
href="#"
onClick={async (e) => {
onClick={(e) => {
e.stopPropagation();
await navigator.clipboard.writeText(
user?.alt_phone_number || "",
);
copyToClipboard(user?.alt_phone_number || "");
setCopied(true);
setTimeout(() => setCopied(false), 2500);
}}
>
<span className="tooltip" id="copy-phoneicon">
<span className="tooltip-text tooltip-top">
Copy Phone number
{t("copy_phone_number")}
</span>
<CareIcon icon="l-clipboard" className="h-5 w-5" />
<CareIcon
icon={copied ? "l-check" : "l-clipboard"}
id="copy-icon"
className="h-5 w-5"
/>
</span>
</a>
<span>{user.alt_phone_number}</span>
Expand Down
Loading