From afe6e257eef5de09ad492ef3a7ba00ac89fb137c Mon Sep 17 00:00:00 2001 From: JULLIEN Baptiste Date: Tue, 30 Apr 2024 15:35:21 +0200 Subject: [PATCH 1/5] feat(front): Add a way to change card_id for any account using readCard component in admin/account page --- .../src/routes/admin/accounts/+page.svelte | 1036 +++++++++-------- 1 file changed, 557 insertions(+), 479 deletions(-) diff --git a/frontend/src/routes/admin/accounts/+page.svelte b/frontend/src/routes/admin/accounts/+page.svelte index 1b0be27..0269fe8 100644 --- a/frontend/src/routes/admin/accounts/+page.svelte +++ b/frontend/src/routes/admin/accounts/+page.svelte @@ -5,6 +5,7 @@ import { accountsApi } from '$lib/requests/requests'; import { formatPrice } from '$lib/utils'; import { onMount } from 'svelte'; + import ReadCard from '$lib/components/readCard.svelte'; let accounts: Account[] = []; let newAccount: NewAccount = { @@ -38,7 +39,8 @@ let deletingAccount: boolean = false; let confirmationMessage: string | undefined = undefined; let deleteAccountCallback: VoidFunction = () => {}; - + let selectedAccount: Account | undefined = undefined; + let askForCard = false; onMount(() => { reloadAccounts(); }); @@ -89,6 +91,34 @@ reloadAccounts(); }); } + + function changeCardId(account: Account | undefined, card_id: string) { + if (account != undefined) { + accountsApi() + .patchAccountId( + account.id, + { + card_id: card_id + }, + { withCredentials: true } + ) + .then((res) => { + account = res.data ?? account; + }) + .catch((err) => { + if (account != undefined) { + account.card_id = account.card_id ?? ''; + } + }); + } else { + console.log('test'); + } + } + + function reset() { + askForCard = false; + selectedAccount = undefined; + } {#if shown_refill} @@ -100,534 +130,582 @@ /> {/if} - - + + + { + changeCardId(selectedAccount, id); + reset(); + }} + /> +{:else} +
-
-
-

- Ajouter un compte -

-
+
+
+
+

+ Ajouter un compte +

+
-
- -
- -
- - -
- -
+
+ +
+ +
+ + +
+ +
- -
- -
+ +
+ +
- -
- -
+ +
+ +
- -
- -
+ +
+ +
- + +
+
-
-
+ {#if deletingAccount} + { + deletingAccount = false; + }} + confirm_callback={deleteAccountCallback} + /> + {/if} -{#if deletingAccount} - { - deletingAccount = false; - }} - confirm_callback={deleteAccountCallback} - /> -{/if} - - -
- -
-
-
-
- + +
+ +
+
+
-
-

Comptes

-

Ajouter des comptes

-
- - -
- { - // @ts-ignore - searchQuery = e.target.value.toLowerCase(); - - reloadAccounts(); - }} - /> - - - - -
+ +
+
+

Comptes

+

Ajouter des comptes

+
-
-
- + +
importAccounts(e)} - /> - + + + +
- -
-
-
- + Importer des Comptes + - - - - - - - - - - - - + + + Ajouter un compte + + + + + - - {#each accounts as account} + +
-
- - Nom - -
-
-
- - Prénom - -
-
-
- - Adresse E-Mail - -
-
-
- - Solde - -
-
-
- - Rôle - -
-
-
- + - Prix - -
-
-
+ - - - + + - {/each} - -
-
- { - // @ts-ignore - let name = e.target?.value; - accountsApi() - .patchAccountId( - account.id, - { - last_name: name - }, - { withCredentials: true } - ) - .then((res) => { - account = res.data ?? account; - }) - .catch((err) => { - account.last_name = account.last_name ?? ''; - }); - }} - /> -
-
-
- { - // @ts-ignore - let name = e.target?.value; - accountsApi() - .patchAccountId( - account.id, - { - first_name: name - }, - { withCredentials: true } - ) - .then((res) => { - account = res.data ?? account; - }) - .catch((err) => { - account.first_name = account.first_name ?? ''; - }); - }} - /> -
-
-
- { - // @ts-ignore - let name = e.target?.value; - accountsApi() - .patchAccountId( - account.id, - { - email_address: name - }, - { withCredentials: true } - ) - .then((res) => { - account = res.data ?? account; - }) - .catch((err) => { - account.email_address = account.email_address ?? ''; - }); - }} - /> +
+
+ + Nom +
- -
-
-

- {formatPrice(account.balance)} -

+ +
+
+ + Prénom +
- -
-
-
+
+ - - - - - - - + Adresse E-Mail +
- -
-
-
+
+ - - - - - - + Solde +
- -
-
-
+
+ - Transactions - -
+
+
+ - Supprimer - + Prix +
- +
- + - -
-
-

- {accounts.length} résultats -

-
+ + {#each accounts as account} + + +
+ { + // @ts-ignore + let name = e.target?.value; + accountsApi() + .patchAccountId( + account.id, + { + last_name: name + }, + { withCredentials: true } + ) + .then((res) => { + account = res.data ?? account; + }) + .catch((err) => { + account.last_name = account.last_name ?? ''; + }); + }} + /> +
+ + +
+ { + // @ts-ignore + let name = e.target?.value; + accountsApi() + .patchAccountId( + account.id, + { + first_name: name + }, + { withCredentials: true } + ) + .then((res) => { + account = res.data ?? account; + }) + .catch((err) => { + account.first_name = account.first_name ?? ''; + }); + }} + /> +
+ + +
+ { + // @ts-ignore + let name = e.target?.value; + accountsApi() + .patchAccountId( + account.id, + { + email_address: name + }, + { withCredentials: true } + ) + .then((res) => { + account = res.data ?? account; + }) + .catch((err) => { + account.email_address = account.email_address ?? ''; + }); + }} + /> +
+ + +
+

+ {formatPrice(account.balance)} +

+
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+ + + {/each} + + + -
-
- + + + + Précédent + -

- Page {page} / {maxPage} -

+

+ Page {page} / {maxPage} +

- + Suivant + + + + +
+
-
+
- -
- + +{/if} From 024fc53e624ddaf4e0ef94ce80c94bee4ef8235e Mon Sep 17 00:00:00 2001 From: JULLIEN Baptiste Date: Tue, 30 Apr 2024 15:36:16 +0200 Subject: [PATCH 2/5] fix(front): remove console.log --- frontend/src/routes/admin/accounts/+page.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/src/routes/admin/accounts/+page.svelte b/frontend/src/routes/admin/accounts/+page.svelte index 0269fe8..4a972f3 100644 --- a/frontend/src/routes/admin/accounts/+page.svelte +++ b/frontend/src/routes/admin/accounts/+page.svelte @@ -110,8 +110,6 @@ account.card_id = account.card_id ?? ''; } }); - } else { - console.log('test'); } } From 65c1c4fb6a5311735786b42d26f1ffd1ba4ce7fe Mon Sep 17 00:00:00 2001 From: JULLIEN Baptiste Date: Tue, 30 Apr 2024 21:49:56 +0200 Subject: [PATCH 3/5] fix(front): disable the button to avoid when enter is pressed to repushed it --- .../src/routes/admin/accounts/+page.svelte | 989 +++++++++--------- 1 file changed, 495 insertions(+), 494 deletions(-) diff --git a/frontend/src/routes/admin/accounts/+page.svelte b/frontend/src/routes/admin/accounts/+page.svelte index 4a972f3..4e115e3 100644 --- a/frontend/src/routes/admin/accounts/+page.svelte +++ b/frontend/src/routes/admin/accounts/+page.svelte @@ -160,550 +160,551 @@ reset(); }} /> -{:else} - +{/if} + +