From b5885b23a8d3593428334683b8c03075ce071f3a Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 21 May 2023 12:26:29 -0600 Subject: Añade edición de método de pago MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/actions.ts | 6 ++++-- src/clients/loaders.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/clients') diff --git a/src/clients/actions.ts b/src/clients/actions.ts index cb5ba23..acc5ad3 100644 --- a/src/clients/actions.ts +++ b/src/clients/actions.ts @@ -32,14 +32,16 @@ export async function editAccount({ request }) { return redirect("/account"); } -export async function editAddress({ params, request }) { +export async function authenticatedEdit({ request }) { clearSessionStorage(); const client = new ApiClient(); + const paths = new URL(request.url).pathname.split('/'); + const request_path = paths.slice(0, paths.length - 1).join('/'); let form_data = await request.formData(); form_data = deleteEmptyFields(form_data); try { - await client.put(`/account/addresses/${params.addressId}`, form_data); + await client.put(request_path, form_data); return redirect("/account"); } catch(error) { diff --git a/src/clients/loaders.ts b/src/clients/loaders.ts index 618e593..7e44f16 100644 --- a/src/clients/loaders.ts +++ b/src/clients/loaders.ts @@ -20,6 +20,17 @@ export async function addressLoader({ params }) { return request; } +export async function cardLoader({ params }) { + const client = new ApiClient(); + const path = `/account/cards/${ params.cardId }`; + const request = await client.authenticatedGet(path); + + if(request.response) + return redirect("/account"); + + return request; +} + export async function accountLoader() { const client = new ApiClient(); -- cgit v1.2.3