Skip to content

Commit f0b3ce8

Browse files
feat: add shop pages (#1200)
* feat: add shop pages * feat: add link to contract on product contract page --------- Co-authored-by: Felix Evers <git@felixevers.de>
1 parent d19e722 commit f0b3ce8

File tree

16 files changed

+602
-138
lines changed

16 files changed

+602
-138
lines changed

customer/api/dataclasses/booked_product.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type Contract = {
2+
uuid: string,
3+
version: string,
4+
name: string,
5+
contractId: string,
6+
url: string,
7+
lastAccepted?: Date,
8+
}

customer/api/dataclasses/customer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Address } from '@/api/dataclasses/address'
2-
import type { BookedProduct } from '@/api/dataclasses/booked_product'
2+
import type { CustomerProduct } from '@/api/dataclasses/customer_product'
33

4-
export type CustomerProductExtension = { products: BookedProduct[] }
4+
export type CustomerProductExtension = { products: CustomerProduct[] }
55

66
export type Customer = {
77
uuid: string,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Contract } from '@/api/dataclasses/contract'
2+
import type { Product } from '@/api/dataclasses/product'
3+
4+
type CustomerProductStatus = 'booked' | 'booking' | 'canceled' | 'inCart'
5+
6+
export type CustomerProduct = {
7+
/** The identifier of the booking
8+
*
9+
* undefined if creating
10+
*/
11+
uuid?: string,
12+
/** The identifier of the booked product */
13+
productUUID: string,
14+
/** The identifier of the customer that booked the product */
15+
customerUUID: string,
16+
/** The date from which the booking starts */
17+
startDate: Date,
18+
/**
19+
* The date from the booking ends
20+
*
21+
* undefined if it is continuous
22+
*/
23+
endDate?: Date,
24+
status: CustomerProductStatus,
25+
/** The contracts used for the booking */
26+
contracts: Contract[],
27+
/** The optionally loaded data of the product */
28+
product?: Product,
29+
// voucherCode: string,
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useQuery } from '@tanstack/react-query'
2+
import { QueryKeys } from '@/api/mutations/query_keys'
3+
import { ContractsAPI } from '@/api/services/contract'
4+
5+
export const useContractQuery = (id?: string) => {
6+
return useQuery({
7+
queryKey: [QueryKeys.contract, id],
8+
enabled: id !== undefined,
9+
queryFn: async () => {
10+
if(id === undefined) {
11+
return
12+
}
13+
return await ContractsAPI.get(id)
14+
},
15+
})
16+
}
17+
18+
export const useContractsQuery = () => {
19+
return useQuery({
20+
queryKey: [QueryKeys.contract, 'all'],
21+
queryFn: async () => {
22+
return await ContractsAPI.getMany()
23+
},
24+
})
25+
}
26+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useQuery } from '@tanstack/react-query'
2+
import { QueryKeys } from '@/api/mutations/query_keys'
3+
import { CustomerProductsAPI } from '@/api/services/customer_product'
4+
5+
export const useCustomerProductsQuery = () => {
6+
return useQuery({
7+
queryKey: [QueryKeys.customerProduct],
8+
queryFn: async () => {
9+
return await CustomerProductsAPI.getMany()
10+
},
11+
})
12+
}

customer/api/mutations/query_keys.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export const QueryKeys = {
22
product: 'product',
33
userSeat: 'user-seat',
44
customer: 'customer',
5-
activeProduct: 'active-products',
5+
customerProduct: 'customer-products',
66
invoice: 'invoice',
77
voucher: 'voucher',
8+
contract: 'contract',
89
}

customer/api/services/contract.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { Contract } from '@/api/dataclasses/contract'
2+
3+
// TODO delete later
4+
export const exampleContracts: Contract[] = [
5+
{
6+
uuid: '1',
7+
name: 'Contract 1',
8+
version: 'v1-2211',
9+
contractId: 'agb',
10+
url: 'https://cdn.helpwave.de/privacy.html',
11+
},
12+
{
13+
uuid: '2',
14+
name: 'Contract 2',
15+
version: 'v2-7110',
16+
contractId: 'agb',
17+
url: 'https://cdn.helpwave.de/privacy.html',
18+
},
19+
{
20+
uuid: '3',
21+
name: 'Contract 3',
22+
version: 'v1-9811',
23+
contractId: 'agb',
24+
url: 'https://cdn.helpwave.de/privacy.html',
25+
}
26+
]
27+
28+
export const ContractsAPI = {
29+
get: async (id: string): Promise<Contract> => {
30+
const contract = exampleContracts.find(value => value.uuid === id)
31+
if (!contract) {
32+
throw new Error('Could not find contract')
33+
}
34+
return contract
35+
},
36+
getMany: async (): Promise<Contract[]> => {
37+
return exampleContracts
38+
},
39+
/**
40+
* Returns all
41+
*/
42+
getForProduct: async (_: string): Promise<Contract[]> => {
43+
return exampleContracts
44+
},
45+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { CustomerProduct } from '@/api/dataclasses/customer_product'
2+
3+
const customerProductsData: CustomerProduct[] = [
4+
{
5+
uuid: '1',
6+
customerUUID: 'customer',
7+
productUUID: '1',
8+
startDate: new Date(2025, 1, 1),
9+
status: 'booked',
10+
contracts: []
11+
}
12+
]
13+
14+
export const CustomerProductsAPI = {
15+
getMany: async () => {
16+
return customerProductsData
17+
},
18+
buy: async (_: CustomerProduct) => {
19+
// TODO
20+
},
21+
update: async (_: CustomerProduct) => {
22+
// TODO
23+
},
24+
}

customer/components/layout/Page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type PageProps = PropsWithChildren<{
3131
footer?: ReactNode,
3232
isHidingSidebar?: boolean,
3333
mainContainerClassName?: string,
34+
contentAndFooterClassName?: string,
3435
}>
3536

3637
const navItems: NavItem[] = [
@@ -51,12 +52,13 @@ export const Page = ({
5152
footer = (<Footer/>),
5253
isHidingSidebar = false,
5354
mainContainerClassName,
55+
contentAndFooterClassName,
5456
}: PageProps) => {
5557
const translation = useTranslation(defaultPageTranslationTranslation)
5658
const [isNavigationVisible, setIsNavigationVisible] = useState(false)
5759

5860
const mainContent = (
59-
<div className={tw('flex flex-col items-center justify-between w-full h-full overflow-y-scroll')}>
61+
<div className={tx('flex flex-col justify-between w-full h-full overflow-y-scroll', contentAndFooterClassName)}>
6062
<main className={tx('@(flex flex-col max-w-[1200px] gap-y-6)', mainContainerClassName)}>
6163
{children}
6264
</main>

0 commit comments

Comments
 (0)