summaryrefslogtreecommitdiff
path: root/src/clients/actions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/clients/actions.ts')
-rw-r--r--src/clients/actions.ts18
1 files changed, 18 insertions, 0 deletions
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