-
Notifications
You must be signed in to change notification settings - Fork 55
Add store policies pages and consent checkboxes #85
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f435a28
Add store policies pages and consent checkboxes
Cichorek 1649845
Add red border and focus to unchecked policy checkbox on validation
Cichorek dc44546
Harden policy consent: fail-closed on API errors, add strict fetcher
Cichorek f902fe3
Limit checkout consent checkbox to Terms of Service for guests only
Cichorek 1be8c81
Simplify policy consent: replace dynamic API fetching with hardcoded …
Cichorek df968cd
Use getClient().policies.get() after getPolicy removal in @spree/next…
Cichorek e1d5c97
Fix PolicyConsent links to include localized basePath
Cichorek b52c5c2
Update README policy description
Cichorek fc7c039
Fix policies import after @spree/next removal
Cichorek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/app/[country]/[locale]/(storefront)/policies/[slug]/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import type { Metadata } from "next"; | ||
| import { notFound } from "next/navigation"; | ||
| import { getPolicy } from "@/lib/data/policies"; | ||
| import { getStoreName } from "@/lib/seo"; | ||
|
|
||
| interface PolicyPageProps { | ||
| params: Promise<{ | ||
| country: string; | ||
| locale: string; | ||
| slug: string; | ||
| }>; | ||
| } | ||
|
|
||
| export async function generateMetadata({ | ||
| params, | ||
| }: PolicyPageProps): Promise<Metadata> { | ||
| const { slug } = await params; | ||
| const policy = await getPolicy(slug); | ||
|
|
||
| if (!policy) { | ||
| return { title: "Policy Not Found" }; | ||
| } | ||
|
|
||
| const storeName = getStoreName(); | ||
|
|
||
| return { | ||
| title: storeName ? `${policy.name} | ${storeName}` : policy.name, | ||
| }; | ||
| } | ||
|
|
||
| export default async function PolicyPage({ params }: PolicyPageProps) { | ||
| const { slug } = await params; | ||
| const policy = await getPolicy(slug); | ||
|
|
||
| if (!policy) { | ||
| notFound(); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12"> | ||
| <h1 className="text-3xl font-bold text-gray-900 mb-8">{policy.name}</h1> | ||
| {policy.body_html ? ( | ||
| <div | ||
| className="prose prose-gray" | ||
| dangerouslySetInnerHTML={{ __html: policy.body_html }} | ||
| /> | ||
| ) : policy.body ? ( | ||
| <div className="prose prose-gray whitespace-pre-wrap"> | ||
| {policy.body} | ||
| </div> | ||
| ) : ( | ||
| <p className="text-gray-500">No content available for this policy.</p> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| "use client"; | ||
|
|
||
| import Link from "next/link"; | ||
| import { usePathname } from "next/navigation"; | ||
| import { Checkbox } from "@/components/ui/checkbox"; | ||
| import { CONSENT_POLICIES } from "@/lib/constants/policies"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { extractBasePath } from "@/lib/utils/path"; | ||
|
|
||
| interface PolicyConsentProps { | ||
| checked: boolean; | ||
| onCheckedChange: (checked: boolean) => void; | ||
| error?: boolean; | ||
| } | ||
|
|
||
| export function PolicyConsent({ | ||
| checked, | ||
| onCheckedChange, | ||
| error, | ||
| }: PolicyConsentProps) { | ||
| const pathname = usePathname(); | ||
| const basePath = extractBasePath(pathname); | ||
| return ( | ||
| <div className="flex items-start gap-2.5"> | ||
| <Checkbox | ||
| id="policy-consent" | ||
| checked={checked} | ||
| onCheckedChange={(value) => onCheckedChange(value === true)} | ||
| className={cn("mt-0.5", error && "border-red-500")} | ||
| /> | ||
| <label | ||
| htmlFor="policy-consent" | ||
| className={cn("text-sm", error ? "text-red-500" : "text-gray-900")} | ||
| > | ||
| I agree to the{" "} | ||
| {CONSENT_POLICIES.map((policy, index) => ( | ||
| <span key={policy.slug}> | ||
| {index > 0 && index < CONSENT_POLICIES.length - 1 && ", "} | ||
| {index > 0 && index === CONSENT_POLICIES.length - 1 && " and "} | ||
| <Link | ||
| href={`${basePath}/policies/${policy.slug}`} | ||
| target="_blank" | ||
| className={cn( | ||
| "underline", | ||
| error | ||
| ? "text-red-500 hover:text-red-700" | ||
| : "text-primary hover:text-primary/70", | ||
| )} | ||
| > | ||
| {policy.name} | ||
| </Link> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </span> | ||
| ))} | ||
| </label> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.