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

Bug/copy token #203

Merged
merged 4 commits into from
Dec 10, 2024
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
7 changes: 5 additions & 2 deletions nextjs-interface/src/app/ui/dashboard/ShowToken.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from "react";
import React, { useEffect } from "react";

import { copyToClipboard } from "@/lib/utils";
import { useFetchToken } from "@/lib/data";

export default function ShowToken({ ip }: { ip: string }) {
const newToken = useFetchToken(ip);
copyToClipboard(newToken);

useEffect(() => {
copyToClipboard(newToken);
}, [newToken]);

return (
<div className="mt-2 bg-zinc-200 p-2 text-sm dark:bg-zinc-800">
Expand Down
21 changes: 13 additions & 8 deletions nextjs-interface/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

// Fonction permettant la copie du Token
export const copyToClipboard = (text: string) => {
navigator.clipboard
.writeText(text)
.then(() => {
console.log("Token copié dans le clipboard");
})
.catch((err) => {
console.error("Copie du Token échoué : ", err);
});
if (navigator.clipboard) {
navigator.clipboard
.writeText(text)
.then(() => {
console.log("Token copié dans le presse-papiers");
})
.catch((err) => {
console.error("Erreur lors de la copie du token : ", err);
});
} else {
console.log("Clipboard inaccessible...");
}
};

export function validateIp(ip: string): boolean {
Expand Down
Loading