Skip to content

Commit

Permalink
fix: reformat
Browse files Browse the repository at this point in the history
Closes: #202
Closes: #194
  • Loading branch information
ColinRgm committed Dec 10, 2024
1 parent f27dd2a commit 4d6e27a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 57 deletions.
36 changes: 18 additions & 18 deletions nextjs-interface/src/app/ui/dashboard/SeeToken.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {Button} from "@/components/ui/button";
import React, {useState} from "react";
import { Button } from "@/components/ui/button";
import React, { useState } from "react";
import ShowToken from "@/app/ui/dashboard/ShowToken";

export default function SeeToken({ip}: { ip: string }) {
const [showToken, setShowToken] = useState(false);
export default function SeeToken({ ip }: { ip: string }) {
const [showToken, setShowToken] = useState(false);

const toggleToken = () => {
setShowToken(!showToken);
};
const toggleToken = () => {
setShowToken(!showToken);
};

return (
<div>
<Button
onClick={toggleToken}
className="p-2 text-white dark:bg-zinc-700 dark:text-white dark:hover:bg-black"
>
{showToken ? "Cacher le Token" : "Afficher et Copier le Token"}
</Button>
{showToken && <ShowToken ip={ip}/>}
</div>
);
return (
<div>
<Button
onClick={toggleToken}
className="p-2 text-white dark:bg-zinc-700 dark:text-white dark:hover:bg-black"
>
{showToken ? "Cacher le Token" : "Afficher et Copier le Token"}
</Button>
{showToken && <ShowToken ip={ip} />}
</div>
);
}
35 changes: 15 additions & 20 deletions nextjs-interface/src/app/ui/dashboard/ShowToken.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import React, {useEffect} from "react";
import React, { useEffect } from "react";

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

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

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

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

return (
<div className="mt-2 bg-zinc-200 p-2 text-sm dark:bg-zinc-800">
Token copié !<br/>
{newToken}
</div>
);


}
return (
<div className="mt-2 bg-zinc-200 p-2 text-sm dark:bg-zinc-800">
Token copié !<br />
{newToken}
</div>
);
}
38 changes: 19 additions & 19 deletions nextjs-interface/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import {type ClassValue, clsx} from "clsx";
import {twMerge} from "tailwind-merge";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
return twMerge(clsx(inputs));
}

// Fonction permettant la copie du Token
export const copyToClipboard = (text: string) => {

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...")
}

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 {
const ipRegex =
/^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/;
return ipRegex.test(ip);
}
const ipRegex =
/^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/;
return ipRegex.test(ip);
}

0 comments on commit 4d6e27a

Please sign in to comment.