'use client'; import React, { useEffect, useState } from 'react'; import { useParams } from 'next/navigation'; import { getShopPolicy, type ShopPolicy } from '@/hooks/use-shopify-policies'; export interface PolicyBodyProps { handle?: string; title?: string; notFoundMessage?: string; } const PolicyBody: React.FC = ({ handle: handleProp, title: titleProp, notFoundMessage = 'This policy has not been published yet.', }) => { const params = useParams(); const handle = handleProp || (params?.handle as string | undefined); const [policy, setPolicy] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (!handle) { setLoading(false); return; } let cancelled = false; setLoading(true); getShopPolicy(handle) .then((result) => { if (!cancelled) setPolicy(result); }) .catch(() => { if (!cancelled) setPolicy(null); }) .finally(() => { if (!cancelled) setLoading(false); }); return () => { cancelled = true; }; }, [handle]); return (

{titleProp || policy?.title || 'Policy'}

{loading ? (
{Array.from({ length: 6 }).map((_, index) => (
))}
) : policy ? (
) : (

{notFoundMessage}

)}
); }; export default PolicyBody;