mirror of
https://github.com/KevinMidboe/planetposen-frontend.git
synced 2025-10-29 13:10:12 +00:00
Updated ts types, sync w/ backend
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
import { writable, get, derived } from 'svelte/store';
|
import { writable, derived } from 'svelte/store';
|
||||||
import type { Writable, Readable } from 'svelte/store';
|
import type { Writable, Readable } from 'svelte/store';
|
||||||
|
import type ICart from './interfaces/ICart';
|
||||||
|
|
||||||
export const cart: Writable<any> = writable([]);
|
export const cart: Writable<ICart[]> = writable([]);
|
||||||
export const isOpen: Writable<boolean> = writable(false);
|
export const isOpen: Writable<boolean> = writable(false);
|
||||||
|
|
||||||
export const count: Readable<number> = derived(cart, ($cart) => $cart.length || 0);
|
export const count: Readable<number> = derived(cart, ($cart) => $cart.length || 0);
|
||||||
|
|
||||||
export const subTotal: Readable<number> = derived(cart, ($cart) => {
|
export const subTotal: Readable<number> = derived(cart, ($cart) => {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
$cart.forEach((cartItem) => (total += cartItem.price * cartItem.quantity));
|
$cart.forEach((cartItem: ICart) => (total += cartItem.price * cartItem.quantity));
|
||||||
return total;
|
return total;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,39 @@
|
|||||||
import type { IProduct } from './IProduct';
|
import type { IProduct } from './IProduct';
|
||||||
import type { IOrder, IOrderSummary } from './IOrder';
|
import type { IOrder, IOrderSummary } from './IOrder';
|
||||||
|
import type ICustomer from './ICustomer';
|
||||||
|
import type ICart from './ICart';
|
||||||
|
|
||||||
export interface IProductResponse {
|
export interface IProductResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
products: Array<IProduct>;
|
products: Array<IProduct>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IOrderResponse {
|
export interface IOrderDTO {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
order: IOrder;
|
order: IOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IOrderCreateDTO {
|
||||||
|
customer: ICustomer;
|
||||||
|
cart: ICart[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface IOrderSummaryResponse {
|
export interface IOrderSummaryResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
order: IOrderSummary;
|
order: IOrderSummary;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IProductResponse {
|
export interface IProductDTO {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
product: IProduct;
|
product: IProduct;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IProductsResponse {
|
export interface IProductsDTO {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
products: Array<IProduct>;
|
products: Array<IProduct>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICartDTO {
|
||||||
|
cart: ICart[];
|
||||||
|
success: boolean;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// import type IProduct from './IProduct';
|
// import type IProduct from './IProduct';
|
||||||
// import type BadgeType from './BadgeType';
|
// import type BadgeType from './BadgeType';
|
||||||
|
import type ICustomer from './ICustomer';
|
||||||
|
|
||||||
export interface IStripePayment {
|
export interface IStripePayment {
|
||||||
amount: number;
|
amount: number;
|
||||||
@@ -26,17 +27,8 @@ export interface IOrder {
|
|||||||
created?: Date;
|
created?: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICustomer {
|
|
||||||
city: string;
|
|
||||||
customer_no: string;
|
|
||||||
email: string;
|
|
||||||
firstname: string;
|
|
||||||
lastname: string;
|
|
||||||
streetaddress: string;
|
|
||||||
zipcode: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ILineItem {
|
export interface ILineItem {
|
||||||
|
sku_id: number;
|
||||||
image: string;
|
image: string;
|
||||||
name: string;
|
name: string;
|
||||||
price: number;
|
price: number;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { dev } from '$app/environment';
|
import { dev } from '$app/environment';
|
||||||
import { cart as cartStore } from './cartStore';
|
import { cart as cartStore } from './cartStore';
|
||||||
|
import type { ICartDTO } from './interfaces/ApiResponse';
|
||||||
|
|
||||||
const WS_HOST = '127.0.0.1';
|
const WS_HOST = '127.0.0.1';
|
||||||
const WS_PORT = 30010;
|
const WS_PORT = 30010;
|
||||||
|
|||||||
@@ -11,11 +11,16 @@
|
|||||||
|
|
||||||
<div class="personalia">
|
<div class="personalia">
|
||||||
<Input id="email" bind:value="{email}" label="E-postaddresse" autocomplete="email" />
|
<Input id="email" bind:value="{email}" label="E-postaddresse" autocomplete="email" />
|
||||||
<Input id="firstName" bind:value="{firstName}" label="Fornavn" autocomplete="given-name" />
|
<Input id="first_name" bind:value="{firstName}" label="Fornavn" autocomplete="given-name" />
|
||||||
<Input id="lastName" bind:value="{lastName}" label="Etternavn" autocomplete="family-name" />
|
<Input id="last_name" bind:value="{lastName}" label="Etternavn" autocomplete="family-name" />
|
||||||
|
|
||||||
<Input id="address" bind:value="{address}" label="Gateadresse" autocomplete="address-line1" />
|
<Input
|
||||||
<Input id="zipCode" bind:value="{zipCode}" label="Postnummer" autocomplete="postal-code" />
|
id="street_address"
|
||||||
|
bind:value="{address}"
|
||||||
|
label="Gateadresse"
|
||||||
|
autocomplete="address-line1"
|
||||||
|
/>
|
||||||
|
<Input id="zip_code" bind:value="{zipCode}" label="Postnummer" autocomplete="postal-code" />
|
||||||
<Input id="city" bind:value="{city}" label="By" autocomplete="address-level2" />
|
<Input id="city" bind:value="{city}" label="By" autocomplete="address-level2" />
|
||||||
|
|
||||||
<div id="personalia-submit-button">
|
<div id="personalia-submit-button">
|
||||||
|
|||||||
@@ -21,23 +21,23 @@
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{#if $cart.length}
|
{#if $cart.length}
|
||||||
{#each $cart as order}
|
{#each $cart as cartItem}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div class="line-order">
|
<div class="line-order">
|
||||||
<a href="/shop/{order.product_no}"><span>{order.name}</span></a>
|
<a href="/shop/{cartItem.product_no}"><span>{cartItem.name}</span></a>
|
||||||
<span class="subtext">Størrelse: {order.size}</span>
|
<span class="subtext">Størrelse: {cartItem.size}</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<QuantitySelect
|
<QuantitySelect
|
||||||
bind:value="{order.quantity}"
|
bind:value="{cartItem.quantity}"
|
||||||
hideButtons="{true}"
|
hideButtons="{true}"
|
||||||
on:decrement="{() => decrementProductInCart(order.lineitem_id)}"
|
on:decrement="{() => decrementProductInCart(cartItem.lineitem_id)}"
|
||||||
on:increment="{() => incrementProductInCart(order.lineitem_id)}"
|
on:increment="{() => incrementProductInCart(cartItem.lineitem_id)}"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>Nok {order.quantity * order.price}</td>
|
<td>Nok {cartItem.quantity * cartItem.price}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
let password: string;
|
let password: string;
|
||||||
let displayMessage: string | null;
|
let displayMessage: string | null;
|
||||||
|
|
||||||
function postLogin(event: any) {
|
function postLogin(event: SubmitEvent) {
|
||||||
displayMessage = null;
|
displayMessage = null;
|
||||||
const formData = new FormData(event.target);
|
const formData = new FormData(event.target as HTMLFormElement);
|
||||||
const data = {};
|
const data = {};
|
||||||
formData.forEach((value, key) => (data[key] = value));
|
formData.forEach((value, key) => (data[key] = value));
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { ICustomer } from '$lib/interfaces/IOrder';
|
import type ICustomer from '$lib/interfaces/ICustomer';
|
||||||
|
|
||||||
export let customer: ICustomer;
|
export let customer: ICustomer;
|
||||||
|
|
||||||
@@ -16,17 +16,17 @@
|
|||||||
|
|
||||||
<li>
|
<li>
|
||||||
<span class="label">Name</span>
|
<span class="label">Name</span>
|
||||||
<span class="name">{customer.firstname} {customer.lastname}</span>
|
<span class="name">{customer.first_name} {customer.last_name}</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<span class="label">Street address</span>
|
<span class="label">Street address</span>
|
||||||
<span>{customer.streetaddress}</span>
|
<span>{customer.street_address}</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<span class="label">Zip & City</span>
|
<span class="label">Zip & City</span>
|
||||||
<span>{zeroPadZip(customer.zipcode)}, {customer.city}</span>
|
<span>{zeroPadZip(customer.zip_code)}, {customer.city}</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<li>
|
<li>
|
||||||
<span class="label">Customer</span>
|
<span class="label">Customer</span>
|
||||||
<span class="name">{order.customer.firstname} {order.customer.lastname}</span>
|
<span class="name">{order.customer.first_name} {order.customer.last_name}</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CircleCheckmark from '$lib/icons/CircleCheckmark.svelte';
|
import CircleCheckmark from '$lib/icons/CircleCheckmark.svelte';
|
||||||
|
|
||||||
import { mockProducts } from '$lib/utils/mock';
|
|
||||||
import type { PageServerData } from './$types';
|
import type { PageServerData } from './$types';
|
||||||
import type { IProduct } from '$lib/interfaces/IProduct';
|
import type { ILineItem, IOrder } from '$lib/interfaces/IOrder';
|
||||||
|
|
||||||
function subTotal(products: Array<IProduct>) {
|
function subTotal(lineItems: Array<ILineItem> = []) {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
products.forEach((product) => (total = total + product.price * product.quantity));
|
lineItems.forEach((lineItem) => (total = total + lineItem.price * lineItem.quantity));
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let data: PageServerData;
|
export let data: PageServerData;
|
||||||
const id = data.id as string;
|
const id = data.id as string;
|
||||||
const email = data.email as string;
|
const email = data.email as string;
|
||||||
|
const order = data.order as IOrder;
|
||||||
|
|
||||||
// export let currentRoute;
|
// export let currentRoute;
|
||||||
// const id = currentRoute?.namedParams?.id;
|
// const id = currentRoute?.namedParams?.id;
|
||||||
// const email = currentRoute?.queryParams?.email;
|
// const email = currentRoute?.queryParams?.email;
|
||||||
|
|
||||||
const products = mockProducts(Math.floor(Math.random() * 8) + 1);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section class="order-confirmation">
|
<section class="order-confirmation">
|
||||||
@@ -31,14 +30,14 @@
|
|||||||
A payment to PLANETPOSEN, AS will appear on your statement with order number:
|
A payment to PLANETPOSEN, AS will appear on your statement with order number:
|
||||||
<span class="underline">{id}</span>.
|
<span class="underline">{id}</span>.
|
||||||
</p>
|
</p>
|
||||||
<p>Order receipt has been email to: <span class="underline">{email}</span></p>
|
<p>En ordrebekreftelse er sent til: <span class="underline">{email}</span></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="order-receipt">
|
<div class="order-receipt">
|
||||||
{#each products as product}
|
{#each order?.lineItems as lineItem}
|
||||||
<p>
|
<p>
|
||||||
<code>{product.name} x{product.quantity}</code>
|
<code>{lineItem.name} x{lineItem.quantity}</code>
|
||||||
<code>{product.currency} {product.price * product.quantity}</code>
|
<code>NOK {lineItem.price * lineItem.quantity}</code>
|
||||||
</p>
|
</p>
|
||||||
{/each}
|
{/each}
|
||||||
<p>
|
<p>
|
||||||
@@ -48,7 +47,7 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
<code>Total</code>
|
<code>Total</code>
|
||||||
<code>NOK {subTotal(products)}</code>
|
<code>NOK {subTotal(order?.lineItems)}</code>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { dev } from '$app/environment';
|
import type { IProductsDTO } from '$lib/interfaces/ApiResponse';
|
||||||
import { env } from '$env/dynamic/private';
|
|
||||||
import type { IProductResponse } from '$lib/interfaces/ApiResponse';
|
|
||||||
|
|
||||||
const domain = 'planet.schleppe.cloud';
|
const domain = 'planet.schleppe.cloud';
|
||||||
const pages: Array<ISitemapPage> = [
|
const pages: Array<ISitemapPage> = [
|
||||||
|
|||||||
Reference in New Issue
Block a user