From 21508a3514500f8f38ddaa8bef7a9cd420d76628 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Mon, 22 May 2023 21:18:20 -0600 Subject: AƱade carrito MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clients/loaders.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/clients/loaders.ts') 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(); + 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}`; -- cgit v1.2.3