summaryrefslogtreecommitdiff
path: root/src/clients
diff options
context:
space:
mode:
Diffstat (limited to 'src/clients')
-rw-r--r--src/clients/actions.ts6
-rw-r--r--src/clients/loaders.ts21
2 files changed, 25 insertions, 2 deletions
diff --git a/src/clients/actions.ts b/src/clients/actions.ts
index acc5ad3..cee9a85 100644
--- a/src/clients/actions.ts
+++ b/src/clients/actions.ts
@@ -56,13 +56,15 @@ export async function authenticatedEdit({ request }) {
}
}
-export async function createAddress({ request }) {
+export async function create({ request }) {
clearSessionStorage();
const client = new ApiClient();
+ const paths = new URL(request.url).pathname.split('/');
+ const request_path = paths.slice(0, paths.length - 1).join('/');
const form_data = await request.formData();
try{
- await client.post('/account/addresses', form_data, client.authorizationHeaders());
+ await client.post(request_path, form_data, client.authorizationHeaders());
return redirect("/account");
} catch(error) {
diff --git a/src/clients/loaders.ts b/src/clients/loaders.ts
index 7e44f16..9f5a131 100644
--- a/src/clients/loaders.ts
+++ b/src/clients/loaders.ts
@@ -1,5 +1,7 @@
import { redirect } from "react-router-dom";
import { ApiClient } from "./api_client";
+import { Product, mapProduct } from "../models/product";
+import Token from "../lib/token";
export async function loader({ request }) {
const client = new ApiClient();
@@ -9,6 +11,25 @@ export async function loader({ request }) {
return response;
}
+export async function cartLoader() {
+ const data = new Array<Product>();
+ const token = new Token();
+ const client = new ApiClient();
+ const request = await client.authenticatedGet("/account/cart");
+
+ if(request.response) {
+ token.logout();
+
+ return redirect("/products")
+ }
+
+ request.data.data.attributes.products.data.map(response_data => {
+ data.push(mapProduct(response_data));
+ });
+
+ return data;
+}
+
export async function addressLoader({ params }) {
const client = new ApiClient();
const path = `/account/addresses/${params.addressId}`;