Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 486efc3

Browse files
committed
fix(function): make success and failed funcions more readable
1 parent 3e00356 commit 486efc3

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

aqueductcore/frontend/src/components/organisms/ExperimentDetailsActionButtons/index.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import toast from "react-hot-toast";
1010
import { useState } from "react";
1111

1212
import { BorderedButtonWithIcon } from "components/atoms/sharedStyledComponents/BorderedButtonWithIcon"
13+
import { copyToClipboardFailedWithMessage, copyToClipboardWithSuccessMessage } from 'helper/functions';
1314
import { useRemoveTagFromExperiment } from "API/graphql/mutations/experiment/removeTagFromExperiment";
1415
import { useAddTagToExperiment } from "API/graphql/mutations/experiment/addTagToExperiment";
1516
import { useRemoveExperiment } from "API/graphql/mutations/experiment/removeExperiment";
@@ -140,16 +141,8 @@ function ExperimentDetailsActionButtons({ isEditable, isDeletable, experimentDet
140141
navigator.clipboard
141142
.writeText(`${window.location.origin}/aqd/experiments/${experimentDetails.eid}`)
142143
.then(
143-
() => {
144-
toast.success("Copied to clipboard!", {
145-
id: "clipboard",
146-
});
147-
},
148-
() => {
149-
toast.error("Failed! \n Please copy page's URL manually.", {
150-
id: "clipboard-failed",
151-
});
152-
}
144+
() => copyToClipboardWithSuccessMessage(), //Success
145+
() => copyToClipboardFailedWithMessage("Failed! \n Please copy page's URL manually.") //Failure
153146
);
154147
}
155148

aqueductcore/frontend/src/components/organisms/ExperimentDetailsData/index.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import LinkIcon from "@mui/icons-material/Link";
33
import toast from "react-hot-toast";
44
import { useState } from "react";
55

6+
import { copyToClipboardFailedWithMessage, copyToClipboardWithSuccessMessage } from "helper/functions";
67
import { useRemoveTagFromExperiment } from "API/graphql/mutations/experiment/removeTagFromExperiment";
78
import { useAddTagToExperiment } from "API/graphql/mutations/experiment/addTagToExperiment";
89
import { dateFormatter, removeFavouriteAndArchivedTag } from "helper/formatters";
@@ -79,16 +80,8 @@ function ExperimentDetailsData({ experimentDetails, isEditable }: experimentDeta
7980
navigator.clipboard
8081
.writeText(experimentDetails.eid)
8182
.then(
82-
() => {
83-
toast.success("Copied to clipboard!", {
84-
id: "clipboard",
85-
});
86-
},
87-
() => {
88-
toast.error("Failed! \n Please copy EID manually.", {
89-
id: "clipboard-failed",
90-
});
91-
}
83+
() => copyToClipboardWithSuccessMessage(), //Success
84+
() => copyToClipboardFailedWithMessage("Failed! \n Please copy EID manually.") //Failure
9285
);
9386
}
9487

aqueductcore/frontend/src/helper/functions.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { DependencyList, FocusEvent, useEffect, useRef } from "react";
2+
import toast from "react-hot-toast";
23
import dayjs from "dayjs";
34

4-
import { SortOrder } from "types/componentTypes";
55
import { ExperimentFileType } from "types/globalTypes";
6+
import { SortOrder } from "types/componentTypes";
67

78
// ################## DOM related functions ################## //
89
export const focusInCurrentTarget = ({
@@ -89,3 +90,15 @@ export function stableSort<T>(array: readonly T[], comparator: (a: T, b: T) => n
8990
export function isNullish(value: unknown): value is null | undefined {
9091
return value === null || value === undefined;
9192
}
93+
94+
// ################## Copy to Clipboard Functions ################## //
95+
export function copyToClipboardWithSuccessMessage(message?: string): void | PromiseLike<void> {
96+
toast.success(message ?? "Copied to clipboard!", {
97+
id: "clipboard",
98+
});
99+
}
100+
export function copyToClipboardFailedWithMessage(message?: string): void | PromiseLike<void> {
101+
toast.error(message ?? "Copy to clipboard Failed!", {
102+
id: "clipboard-failed",
103+
});
104+
}

0 commit comments

Comments
 (0)