Skip to content

Commit

Permalink
Merge branch 'main' into slim
Browse files Browse the repository at this point in the history
  • Loading branch information
Rignchen committed Jul 5, 2024
2 parents ba0f7a9 + a856bbf commit 8a082f3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 24 deletions.
7 changes: 7 additions & 0 deletions database/migration/deploy/2024-07-05.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Deploy climat-guardian:2024-07-05 to pg

BEGIN;

grant delete on api.users to web_user; -- any user can remove users

COMMIT;
7 changes: 7 additions & 0 deletions database/migration/revert/2024-07-05.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert climat-guardian:2024-07-05 from pg

BEGIN;

revoke delete on api.users from web_user; -- any user can remove users

COMMIT;
1 change: 1 addition & 0 deletions database/migration/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ roles 2024-06-07T18:32:02Z Nils <nils@fedora> # create the role used by the user
data 2024-06-07T20:09:18Z Nils <nils@fedora> # Add table to store data
user 2024-06-07T20:47:39Z Nils <nils@fedora> # create a user table to store every user and password
esp 2024-06-26T08:20:01Z dylan <dylanbossoku@dylan> # create a esp table to stove every esp data
2024-07-05 2024-07-05T08:58:10Z Nils <nils@fedora> # Grant user the ability to remove users
7 changes: 7 additions & 0 deletions database/migration/verify/2024-07-05.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Verify climat-guardian:2024-07-05 on pg

BEGIN;

-- XXX Add verifications here.

ROLLBACK;
86 changes: 62 additions & 24 deletions nextjs-interface/src/app/ui/dashboard/RenameElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
export default function RenameElement({ id }: { id: string }) {
const [newName, setNewName] = useState("");
const [confirm, setConfirm] = React.useState(false);
const [showToken, setShowToken] = useState(false);
const token = getToken();

const updateEspName = async (newName: string) => {
const url = `/postgrest/esp?id=eq.${id}`;
const response = await fetch(url, {
Expand All @@ -30,40 +33,75 @@ export default function RenameElement({ id }: { id: string }) {
} else {
}
};

const copyToClipboard = (text: string) => {
navigator.clipboard
.writeText(text)
.then(() => {
console.log("Token copied to clipboard");
})
.catch((err) => {
console.error("Failed to copy token: ", err);
});
};

const toggleAndCopyToken = () => {
setShowToken(!showToken);
if (!showToken && token) {
copyToClipboard(token);
} else {
return null;
}
};

return (
<div className="flex cursor-pointer gap-2">
<Popover>
<PopoverTrigger asChild>
<EllipsisVertical />
</PopoverTrigger>
<PopoverContent className="flex w-60 gap-2 dark:bg-zinc-800">
<Input
type="text"
placeholder="modifier l'esp"
value={newName}
className="dark:bg-zinc-800"
onChange={(e) => {
setNewName(e.target.value);
setConfirm(true);
}}
/>
{confirm ? (
<Button
onClick={async () => {
try {
await updateEspName(newName);
setConfirm(false);
} catch (e) {
console.error(e);
}
<PopoverContent className="mr-5 mt-2 flex w-fit flex-col gap-2 dark:bg-zinc-800">
<div className="flex flex-row gap-x-5">
<Input
type="text"
placeholder="modifier l'esp"
value={newName}
className="dark:bg-zinc-800"
onChange={(e) => {
setNewName(e.target.value);
setConfirm(true);
}}
/>
{confirm && (
<Button
onClick={async () => {
try {
await updateEspName(newName);
setConfirm(false);
} catch (e) {
console.error(e);
}
}}
className="p-2 text-white dark:bg-zinc-700 dark:text-white dark:hover:bg-black"
>
Confirm
</Button>
)}
</div>
<div>
<Button
onClick={toggleAndCopyToken}
className="p-2 text-white dark:bg-zinc-700 dark:text-white dark:hover:bg-black"
>
Confirm
{showToken ? "Cacher le Token" : "Afficher et Copier le Token"}
</Button>
) : (
""
)}
{showToken && (
<div className="mt-2 bg-zinc-200 p-2 text-sm dark:bg-zinc-800">
Token copier !: <br />
{token}
</div>
)}
</div>
</PopoverContent>
</Popover>
</div>
Expand Down

0 comments on commit 8a082f3

Please sign in to comment.