Skip to content

Commit

Permalink
✨ display homePage
Browse files Browse the repository at this point in the history
  • Loading branch information
DuvCharles committed Sep 26, 2023
1 parent 6e1c070 commit d2413ee
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/cart/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server';

import { addToCart, createCart, getCart, removeFromCart, updateCart } from 'lib/shopify';
import { addToCart, createCart, getCart, removeFromCart, updateCart } from 'lib/sylius';
import { cookies } from 'next/headers';

export const addItem = async (variantId: string | undefined): Promise<String | undefined> => {
Expand Down
2 changes: 1 addition & 1 deletion components/cart/add-to-cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PlusIcon } from '@heroicons/react/24/outline';
import clsx from 'clsx';
import { addItem } from 'components/cart/actions';
import LoadingDots from 'components/loading-dots';
import { ProductVariant } from 'lib/shopify/types';
import { ProductVariant } from 'lib/sylius/types';
import { useRouter, useSearchParams } from 'next/navigation';
import { useTransition } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion components/layout/footer-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import clsx from 'clsx';
import { Menu } from 'lib/shopify/types';
import { Menu } from 'lib/sylius/types';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { useEffect, useState } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion components/product/product-description.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AddToCart } from 'components/cart/add-to-cart';
import Price from 'components/price';
import Prose from 'components/prose';
import { Product } from 'lib/shopify/types';
import { Product } from 'lib/sylius/types';
import { VariantSelector } from './variant-selector';

export function ProductDescription({ product }: { product: Product }) {
Expand Down
65 changes: 59 additions & 6 deletions lib/sylius/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
import { SYLIUS_API_ENDPOINT } from 'lib/constants';

const domain = `${process.env.SYLIUS_STORE_DOMAIN}`;
const endpoint = `${domain}${SYLIUS_API_ENDPOINT}`;
const DOMAIN = `${process.env.SYLIUS_STORE_DOMAIN}`;
const ENDPOINT = `${DOMAIN}${SYLIUS_API_ENDPOINT}`;

// Fetch
export default async function syliusRequest(
method: string,
path = '',
payload?: Record<string, unknown> | undefined
) {
const options: RequestInit = {
method,
headers: {
'Content-Type': 'application/json'
}
};

if (payload) {
options.body = JSON.stringify(payload);
}

try {
const result = await fetch(`${ENDPOINT}${path}`, options);

const body = await result.json();

if (body.errors) {
throw body.errors[0];
}

return {
status: result.status,
body
};
} catch (e) {
throw {
error: e
};
}
}

// Pages
export const getPages = () => [];
Expand All @@ -15,11 +52,27 @@ export const getCollection = () => {};
export const getCollectionProducts = () => [];

// Cart
export const createCart = () => {};
export const getCart = () => {};
export const addToCart = () => {};
export const createCart = async () => {
const cart = await syliusRequest('POST', '/orders', { localeCode: 'fr_FR' });
return cart;
};
export const getCart = (cartId: string) => {
syliusRequest(REST_METHODS.GET, `/orders/${cartId}`);
return {};
};
export const addToCart = (cartId: string | undefined, payload: AddToCartPayload[]) => {
syliusRequest(REST_METHODS.PUT, `/orders/${cartId}/items`, payload[0]);
return {};
};
export const removeFromCart = () => {};
export const updateCart = () => {};

// Site
export const getMenu = () => [];
export const getMenu = () => [
{
title: 'Home',
path: '/'
}
];

type AddToCartPayload = { merchandiseId: string; quantity: number };

0 comments on commit d2413ee

Please sign in to comment.