From f94e4669f8b05669c3cb476a8c34715e45edde37 Mon Sep 17 00:00:00 2001 From: seaznCode Date: Wed, 11 Mar 2026 22:35:24 +0100 Subject: [PATCH] feat: update contract and template management to streamline type handling and permissions --- .../components/contractEditor.tsx | 41 +++++++++++-------- .../components/contractTemplateList.tsx | 18 ++++---- src/app/coffee-abonnements/summary/page.tsx | 25 +---------- src/app/components/nav/Header.tsx | 32 +++++++++++---- 4 files changed, 62 insertions(+), 54 deletions(-) diff --git a/src/app/admin/contract-management/components/contractEditor.tsx b/src/app/admin/contract-management/components/contractEditor.tsx index 24b2483..3db037b 100644 --- a/src/app/admin/contract-management/components/contractEditor.tsx +++ b/src/app/admin/contract-management/components/contractEditor.tsx @@ -18,7 +18,7 @@ export default function ContractEditor({ onSaved, editingTemplateId, onCancelEdi const [statusMsg, setStatusMsg] = useState(null); const [lang, setLang] = useState<'en' | 'de'>('en'); - const [type, setType] = useState<'contract' | 'bill' | 'invoice' | 'other'>('contract'); + const [type, setType] = useState<'contract' | 'invoice' | 'other'>('contract'); const [contractType, setContractType] = useState<'contract' | 'gdpr'>('contract'); const [userType, setUserType] = useState<'personal' | 'company' | 'both'>('personal'); const [description, setDescription] = useState(''); @@ -54,7 +54,7 @@ export default function ContractEditor({ onSaved, editingTemplateId, onCancelEdi setHtmlCode(tpl.html || ''); setDescription(((tpl as any)?.description as string) || ''); // FIX: DocumentTemplate may not declare `description` setLang((tpl.lang as any) || 'en'); - setType(((tpl.type as any) || 'contract') as 'contract' | 'bill' | 'invoice' | 'other'); + setType(((tpl.type as any) || 'contract') as 'contract' | 'invoice' | 'other'); setContractType(((tpl.contract_type as any) || 'contract') as 'contract' | 'gdpr'); setUserType(((tpl.user_type as any) || 'both') as 'personal' | 'company' | 'both'); setEditingMeta({ @@ -214,8 +214,12 @@ export default function ContractEditor({ onSaved, editingTemplateId, onCancelEdi }; const save = async (publish: boolean) => { - if (publish && type === 'contract') { - const kind = contractType === 'gdpr' ? 'GDPR' : 'Contract'; + if (publish) { + let kind = type === 'contract' + ? (contractType === 'gdpr' ? 'GDPR' : 'Contract') + : type === 'invoice' + ? 'Invoice' + : 'Other'; setPublishConfirmMessage(`This will deactivate other active ${kind} templates that apply to the same user type and language.`) setPublishConfirmOpen(true) return @@ -283,12 +287,15 @@ export default function ContractEditor({ onSaved, editingTemplateId, onCancelEdi
@@ -303,16 +310,18 @@ export default function ContractEditor({ onSaved, editingTemplateId, onCancelEdi )} - + {type !== 'invoice' && ( + + )} {filtered.map((c) => (
-
-

{c.name}

+

{c.name}

+
{c.type && ( - {c.type === 'contract' ? 'Contract' : c.type === 'bill' ? 'Bill' : c.type === 'invoice' ? 'Invoice' : 'Other'} + {c.type === 'contract' ? 'Contract' : c.type === 'invoice' ? 'Invoice' : 'Other'} )} {c.type === 'contract' && ( @@ -171,7 +175,7 @@ export default function ContractTemplateList({ refreshKey = 0, onEdit }: Props) {c.contract_type === 'gdpr' ? 'GDPR' : 'Contract'} )} - {c.user_type && ( + {c.user_type && c.type !== 'invoice' && ( {c.user_type === 'personal' ? 'Personal' : c.user_type === 'company' ? 'Company' : 'Both'} diff --git a/src/app/coffee-abonnements/summary/page.tsx b/src/app/coffee-abonnements/summary/page.tsx index 540f699..b3b549d 100644 --- a/src/app/coffee-abonnements/summary/page.tsx +++ b/src/app/coffee-abonnements/summary/page.tsx @@ -327,30 +327,7 @@ export default function SummaryPage() { > Fill fields with logged in data -
- - -
+ {/* "For someone else" is disabled for now — only self-subscriptions */}
{/* inputs translated */}
diff --git a/src/app/components/nav/Header.tsx b/src/app/components/nav/Header.tsx index 3b6e21f..194483c 100644 --- a/src/app/components/nav/Header.tsx +++ b/src/app/components/nav/Header.tsx @@ -80,6 +80,7 @@ export default function Header({ setGlobalLoggingOut }: HeaderProps) { : 'relative' const [hasReferralPerm, setHasReferralPerm] = useState(false) + const [hasSubscribePerm, setHasSubscribePerm] = useState(false) const [canSeeDashboard, setCanSeeDashboard] = useState(false) const headerElRef = useRef(null) @@ -169,14 +170,20 @@ export default function Header({ setGlobalLoggingOut }: HeaderProps) { } if (!user) { console.log('ℹ️ Header: no user, clearing permission flag') - if (!cancelled) setHasReferralPerm(false) + if (!cancelled) { + setHasReferralPerm(false) + setHasSubscribePerm(false) + } return } const uid = (user as any)?.id ?? (user as any)?._id ?? (user as any)?.userId if (!uid) { console.warn('⚠️ Header: user id missing, cannot fetch permissions', user) - if (!cancelled) setHasReferralPerm(false) + if (!cancelled) { + setHasReferralPerm(false) + setHasSubscribePerm(false) + } return } @@ -216,20 +223,31 @@ export default function Header({ setGlobalLoggingOut }: HeaderProps) { body let can = false + let canSub = false if (Array.isArray(permsSrc)) { // Could be array of strings or objects can = permsSrc.includes?.('can_create_referrals') || permsSrc.some?.((p: any) => p?.name === 'can_create_referrals' || p?.key === 'can_create_referrals') + canSub = + permsSrc.includes?.('can_subscribe') || + permsSrc.some?.((p: any) => p?.name === 'can_subscribe' || p?.key === 'can_subscribe') } else if (permsSrc && typeof permsSrc === 'object') { can = !!permsSrc.can_create_referrals + canSub = !!permsSrc.can_subscribe } - console.log('✅ Header: can_create_referrals =', can) - if (!cancelled) setHasReferralPerm(!!can) + console.log('✅ Header: can_create_referrals =', can, 'can_subscribe =', canSub) + if (!cancelled) { + setHasReferralPerm(!!can) + setHasSubscribePerm(!!canSub) + } } catch (e) { console.error('❌ Header: fetch permissions error:', e) - if (!cancelled) setHasReferralPerm(false) + if (!cancelled) { + setHasReferralPerm(false) + setHasSubscribePerm(false) + } } } @@ -487,7 +505,7 @@ export default function Header({ setGlobalLoggingOut }: HeaderProps) { )} - {DISPLAY_ABONEMENTS && ( + {DISPLAY_ABONEMENTS && hasSubscribePerm && ( )} - {DISPLAY_ABONEMENTS && ( + {DISPLAY_ABONEMENTS && hasSubscribePerm && (