Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added more pages #4

Merged
merged 5 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: ✨ add main policies page
  • Loading branch information
joshistoast committed Jun 16, 2023
commit b79ed4f41132468daa4674f1f20e2239d5e10a90
30 changes: 30 additions & 0 deletions src/lib/server/data/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,36 @@ export const UPDATE_CART_BUYER = gql`
}
`

export const POLICIES_QUERY = gql`
fragment PolicyIndex on ShopPolicy {
id
title
handle
}

query PoliciesIndex {
shop {
privacyPolicy {
...PolicyIndex
}
shippingPolicy {
...PolicyIndex
}
termsOfService {
...PolicyIndex
}
refundPolicy {
...PolicyIndex
}
subscriptionPolicy {
id
title
handle
}
}
}
`

export const POLICY_CONTENT_QUERY = gql`
fragment Policy on ShopPolicy {
body
Expand Down
4 changes: 4 additions & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export enum CartAction {
UPDATE_DISCOUNT = 'UPDATE_DISCOUNT',
UPDATE_BUYER_IDENTITY = 'UPDATE_BUYER_IDENTITY',
}

export type NonNullableFields<T> = {
[P in keyof T]: NonNullable<T[P]>;
}
30 changes: 30 additions & 0 deletions src/routes/[[locale]]/policies/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { PageServerLoad } from './$types'
import { POLICIES_QUERY } from '$lib/server/data'
import invariant from 'tiny-invariant'
import type { Shop, NonNullableFields, ShopPolicy } from '$lib/types'
import { error } from '@sveltejs/kit'

export const load: PageServerLoad = async ({ locals }) => {
const { storefront } = locals

const { data } = await storefront.query<{shop: Shop}>({
query: POLICIES_QUERY,
})
invariant(data, 'No data returned from shopify API')

const { shop } = data

const policies = Object.values(
shop as NonNullableFields<typeof shop>,
).filter(Boolean) as ShopPolicy[]

if (!policies.length)
throw error(404, 'No policies found')

return {
seo: {
title: 'Policies',
},
policies,
}
}
15 changes: 15 additions & 0 deletions src/routes/[[locale]]/policies/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script lang="ts">
import type { PageServerData } from './$types'
import LocaleLink from '$lib/components/LocaleLink.svelte'

export let data: PageServerData
const { policies } = data
</script>

{#each policies as policy}
{#if policy.title}
<LocaleLink href="/policies/{policy.handle}">
<h2>{policy.title}</h2>
</LocaleLink>
{/if}
{/each}
3 changes: 3 additions & 0 deletions src/routes/[[locale]]/policies/[handle]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script lang="ts">
import type { PageServerData } from './$types'
import LocaleLink from '$lib/components/LocaleLink.svelte'

export let data: PageServerData
$: ({ policy } = data)
</script>

<h1>{policy.title}</h1>
<LocaleLink href="/policies">Back to Policies</LocaleLink>

<div>{@html policy.body}</div>