From cbebedd51e1b4a2f709341b792dd073bac83f15d Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Fri, 12 May 2023 23:01:55 -0600 Subject: Añadido formulario de edición de cuenta MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/actions.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/clients/actions.ts (limited to 'src/clients/actions.ts') diff --git a/src/clients/actions.ts b/src/clients/actions.ts new file mode 100644 index 0000000..36935cb --- /dev/null +++ b/src/clients/actions.ts @@ -0,0 +1,18 @@ +import { redirect } from "react-router-dom"; +import { ApiClient } from "./api_client"; +import { deleteEmptyFields } from "../lib/form_utils"; + +export async function editAccount({ request }) { + const client = new ApiClient(); + let form_data = await request.formData(); + form_data = deleteEmptyFields(form_data); + const response = await client.put("/account", form_data); + + if(response.status == 401) + return redirect("/products"); + + client.token.set(response.data.token); + client.token.setRefresh(response.data.refresh); + + return redirect("/account"); +} \ No newline at end of file -- cgit v1.2.3