-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |