Skip to content

Commit

Permalink
add Privacy Policy Page
Browse files Browse the repository at this point in the history
  • Loading branch information
milewskibogumil committed Oct 19, 2024
1 parent c2ed989 commit 5ba8196
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 9 deletions.
10 changes: 9 additions & 1 deletion apps/astro/src/components/ui/portable-text/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ const valueArray = Array.isArray(value) ? value : [value]
<style lang="scss">
[data-portable-text] {
:global(> *:not(:last-child)) {
margin-bottom: calc(8rem / 16);
margin-bottom: 0.5rem;
}
:global(ul) {
padding-left: 1.25rem;
list-style-type: disc;
margin-top: 0.5rem;
:global(li:not(:last-child)) {
margin-bottom: 0.25rem;
}
}
}
</style>
80 changes: 80 additions & 0 deletions apps/astro/src/pages/polityka-prywatnosci.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
import Layout from '@/src/layouts/Layout.astro'
import metadataFetch from '@/utils/metadata.fetch'
import sanityFetch from '@/utils/sanity.fetch'
import Breadcrumbs from '@/components/ui/Breadcrumbs.astro'
import PortableText, { PortableTextQuery, type PortableTextValue } from '@/components/ui/portable-text'
const metadata = await metadataFetch('PrivacyPolicy_Page')
const data = await sanityFetch<{
name: string
slug: string
header: {
heading: PortableTextValue
paragraph: PortableTextValue
}
content: PortableTextValue
}>({
query: `
*[_type == "PrivacyPolicy_Page"][0] {
"name": title,
"slug": slug.current,
header {
${PortableTextQuery('heading')}
${PortableTextQuery('paragraph')}
},
${PortableTextQuery('content')}
}
`,
})
---

<Layout {...metadata}>
<Breadcrumbs data={[{ name: data.name, path: data.slug }]} />
<section class="header">
<PortableText value={data.header.heading} heading="h1" class="heading h2" />
<PortableText value={data.header.paragraph} />
</section>
<section class="content">
<PortableText value={data.content} />
</section>
</Layout>

<style lang="scss">
.header,
.content {
max-width: 41rem;
margin: 0 auto;
}
.header {
margin-top: clamp(2rem, calc(3vw / 0.48), 5rem);
.heading {
margin-bottom: clamp(0.75rem, calc(1vw / 0.48), 1rem);
}
}
.content {
padding: clamp(3rem, calc(5vw / 0.48), 6rem) 0;
counter-reset: counter;
:global(h2) {
&:not(:first-child) {
margin-top: clamp(3rem, calc(4vw / 0.48), 5rem);
}
font-size: clamp(1.25rem, calc(1.5vw / 0.48), 1.5rem);
margin-bottom: clamp(1rem, calc(1.75vw / 0.48), 1.75rem) !important;
counter-increment: counter;
display: grid;
grid-template-columns: 1.5rem 1fr;
gap: 0.5rem;
&::before {
content: counter(counter);
}
}
@media (min-width: 31.25rem) {
padding-left: 2rem;
:global(h2) {
margin-left: -2rem;
}
}
}
</style>
61 changes: 61 additions & 0 deletions apps/sanity/schema/singleTypes/PrivacyPolicy_Page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { defineField, defineType } from "sanity"
import { defineSlugForDocument } from "../../utils/define-slug-for-document";
import { PortableText } from "../ui/portable-text";

const name = 'PrivacyPolicy_Page';
const title = 'Polityka Prywatności';
const slug = '/polityka-prywatnosci';
const icon = () => '📄';

export default defineType({
name: name,
type: 'document',
title: title,
icon,
fields: [
...defineSlugForDocument({ slug: slug }),
defineField({
name: 'header',
type: 'object',
title: 'Sekcja nagłówkowa',
fields: [
defineField({
name: 'heading',
type: 'Heading',
title: 'Nagłówek',
validation: Rule => Rule.required()
}),
defineField({
name: 'paragraph',
type: 'PortableText',
title: 'Paragraf',
validation: Rule => Rule.required(),
}),
],
validation: Rule => Rule.required()
}),
PortableText({
name: 'content',
title: 'Treść',
allowHeadings: true
}),
defineField({
name: 'seo',
type: 'seo',
title: 'SEO',
group: 'seo',
}),
],
groups: [
{
name: 'seo',
title: 'SEO',
},
],
preview: {
prepare: () => ({
title: title,
subtitle: slug
})
}
});
24 changes: 16 additions & 8 deletions apps/sanity/schema/ui/portable-text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { defineField, defineType, useClient } from "sanity";
import { defineField } from "sanity";
import { CustomInput } from "./CustomInput";
import { isValidUrl } from "../../../utils/is-valid-url";
import { InternalLinkableTypes } from "../../../structure/internal-linkable-types";

export default defineType({
name: 'PortableText',
export const PortableText = ({ name, title, allowHeadings = false }: { name?: string, title?: string, allowHeadings?: boolean }) => defineField({
name: name || 'PortableText',
type: 'array',
title: 'Portable Text',
title: title || 'Portable Text',
components: {
// @ts-ignore
input: CustomInput
},
of: [{
type: 'block',
styles: [{ title: 'Normal', value: 'normal' }],
styles: [
{ title: 'Normal', value: 'normal' },
...(allowHeadings ? [
{ title: 'Heading 2', value: 'h2' },
{ title: 'Heading 3', value: 'h3' }
] : [])
],
lists: [
{ title: 'Bullet', value: 'bullet' },
{ title: 'Numbered', value: 'number' }
Expand Down Expand Up @@ -46,15 +52,15 @@ export default defineType({
name: 'external',
type: 'string',
title: 'URL',
description: 'Specify the full URL. Ensure it starts with "https://" and is a valid URL.',
description: 'Specify the full URL. Ensure it starts with "https://", "mailto:" or "tel:" protocol.',
hidden: ({ parent }) => parent?.type !== 'external',
validation: (Rule) => [
Rule.custom((value, { parent }) => {
const type = (parent as { type?: string })?.type;
if (type === 'external') {
if (!value) return "URL is required";
if (!value.startsWith('https://')) {
return 'External link must start with the "https://" protocol';
if (!value.startsWith('https://') && !value.startsWith('mailto:') && !value.startsWith('tel:')) {
return 'External link must start with the "https://", "mailto:" or "tel:" protocol';
}
if (!isValidUrl(value)) return 'Invalid URL';
}
Expand Down Expand Up @@ -87,3 +93,5 @@ export default defineType({
}
}],
});

export default PortableText({});
1 change: 1 addition & 0 deletions apps/sanity/structure/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const structure: StructureResolver = (S) =>
createSingleton(S, "Projects_Page"),
createSingleton(S, "About_Page"),
createSingleton(S, "Contact_Page"),
createSingleton(S, "PrivacyPolicy_Page"),
createSingleton(S, "NotFound_Page"),
S.divider(),
createCollection(S, "Faq_Collection"),
Expand Down
1 change: 1 addition & 0 deletions apps/sanity/structure/internal-linkable-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const InternalLinkableTypes: { type: string }[] = [
{ type: 'Projects_Page' },
{ type: 'About_Page' },
{ type: 'Contact_Page' },
{ type: 'PrivacyPolicy_Page' },
];
2 changes: 2 additions & 0 deletions apps/sanity/structure/schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Index_Page from '../schema/singleTypes/Index_Page';
import Contact_Page from '../schema/singleTypes/Contact_Page';
import Projects_Page from '../schema/singleTypes/Projects_Page';
import About_Page from '../schema/singleTypes/About_Page';
import PrivacyPolicy_Page from '../schema/singleTypes/PrivacyPolicy_Page';
import NotFound_Page from '../schema/singleTypes/NotFound_Page';

const singleTypes = [
Expand All @@ -14,6 +15,7 @@ const singleTypes = [
Projects_Page,
About_Page,
Contact_Page,
PrivacyPolicy_Page,
NotFound_Page,
];

Expand Down

0 comments on commit 5ba8196

Please sign in to comment.