feat: implement header/footer visibility controls for checkout and thankyou pages

- Created LayoutWrapper component to conditionally render header/footer based on route
- Created MinimalHeader component (logo only)
- Created MinimalFooter component (trust badges + policy links)
- Created usePageVisibility hook to get visibility settings per page
- Wrapped ClassicLayout with LayoutWrapper for conditional rendering
- Header/footer visibility now controlled directly in React SPA
- Settings: show/minimal/hide for both header and footer
- Background color support for checkout and thankyou pages
This commit is contained in:
Dwindi Ramadhana
2025-12-25 22:20:48 +07:00
parent c37ecb8e96
commit 9ac09582d2
104 changed files with 14801 additions and 1213 deletions

View File

@@ -0,0 +1,126 @@
import React, { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { SettingsLayout } from '@/routes/Settings/components/SettingsLayout';
import { SettingsCard } from '@/routes/Settings/components/SettingsCard';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { toast } from 'sonner';
import { api } from '@/lib/api';
import { ArrowLeft, Save } from 'lucide-react';
import { useNavigate, useParams } from 'react-router-dom';
export default function EmailTemplates() {
const navigate = useNavigate();
const { template } = useParams();
const queryClient = useQueryClient();
const [subject, setSubject] = useState('');
const [content, setContent] = useState('');
const { data: templateData, isLoading } = useQuery({
queryKey: ['newsletter-template', template],
queryFn: async () => {
const response = await api.get(`/newsletter/template/${template}`);
return response.data;
},
enabled: !!template,
});
React.useEffect(() => {
if (templateData) {
setSubject(templateData.subject || '');
setContent(templateData.content || '');
}
}, [templateData]);
const saveTemplate = useMutation({
mutationFn: async () => {
await api.post(`/newsletter/template/${template}`, {
subject,
content,
});
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['newsletter-template'] });
toast.success('Template saved successfully');
},
onError: () => {
toast.error('Failed to save template');
},
});
const handleSave = () => {
saveTemplate.mutate();
};
return (
<SettingsLayout
title={`Edit ${template === 'welcome' ? 'Welcome' : 'Confirmation'} Email Template`}
description="Customize the email template sent to newsletter subscribers"
>
<div className="mb-4">
<Button variant="ghost" onClick={() => navigate('/marketing/newsletter')}>
<ArrowLeft className="mr-2 h-4 w-4" />
Back to Newsletter
</Button>
</div>
<SettingsCard
title="Email Template"
description="Use variables like {site_name}, {email}, {unsubscribe_url}"
>
<div className="space-y-4">
<div>
<Label htmlFor="subject">Email Subject</Label>
<Input
id="subject"
value={subject}
onChange={(e) => setSubject(e.target.value)}
placeholder="Welcome to {site_name} Newsletter!"
/>
</div>
<div>
<Label htmlFor="content">Email Content</Label>
<Textarea
id="content"
value={content}
onChange={(e) => setContent(e.target.value)}
rows={15}
placeholder="Thank you for subscribing to our newsletter!&#10;&#10;You'll receive updates about our latest products and offers.&#10;&#10;Best regards,&#10;{site_name}"
/>
<p className="text-sm text-muted-foreground mt-2">
Available variables: <code>{'{site_name}'}</code>, <code>{'{email}'}</code>, <code>{'{unsubscribe_url}'}</code>
</p>
</div>
<div className="flex justify-end gap-2">
<Button variant="outline" onClick={() => navigate('/marketing/newsletter')}>
Cancel
</Button>
<Button onClick={handleSave} disabled={saveTemplate.isPending}>
<Save className="mr-2 h-4 w-4" />
{saveTemplate.isPending ? 'Saving...' : 'Save Template'}
</Button>
</div>
</div>
</SettingsCard>
<SettingsCard
title="Preview"
description="Preview how your email will look"
>
<div className="border rounded-lg p-6 bg-muted/50">
<div className="mb-4">
<strong>Subject:</strong> {subject.replace('{site_name}', 'Your Store')}
</div>
<div className="whitespace-pre-wrap">
{content.replace('{site_name}', 'Your Store').replace('{email}', 'customer@example.com')}
</div>
</div>
</SettingsCard>
</SettingsLayout>
);
}

View File

@@ -0,0 +1,201 @@
import React, { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { SettingsLayout } from '@/routes/Settings/components/SettingsLayout';
import { SettingsCard } from '@/routes/Settings/components/SettingsCard';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Download, Trash2, Mail, Search } from 'lucide-react';
import { toast } from 'sonner';
import { api } from '@/lib/api';
import { useNavigate } from 'react-router-dom';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
export default function NewsletterSubscribers() {
const [searchQuery, setSearchQuery] = useState('');
const queryClient = useQueryClient();
const navigate = useNavigate();
const { data: subscribersData, isLoading } = useQuery({
queryKey: ['newsletter-subscribers'],
queryFn: async () => {
const response = await api.get('/newsletter/subscribers');
return response.data;
},
});
const deleteSubscriber = useMutation({
mutationFn: async (email: string) => {
await api.delete(`/newsletter/subscribers/${encodeURIComponent(email)}`);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['newsletter-subscribers'] });
toast.success('Subscriber removed successfully');
},
onError: () => {
toast.error('Failed to remove subscriber');
},
});
const exportSubscribers = () => {
if (!subscribersData?.subscribers) return;
const csv = ['Email,Subscribed Date'].concat(
subscribersData.subscribers.map((sub: any) =>
`${sub.email},${sub.subscribed_at || 'N/A'}`
)
).join('\n');
const blob = new Blob([csv], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `newsletter-subscribers-${new Date().toISOString().split('T')[0]}.csv`;
a.click();
window.URL.revokeObjectURL(url);
};
const subscribers = subscribersData?.subscribers || [];
const filteredSubscribers = subscribers.filter((sub: any) =>
sub.email.toLowerCase().includes(searchQuery.toLowerCase())
);
return (
<SettingsLayout
title="Newsletter Subscribers"
description="Manage your newsletter subscribers and send campaigns"
>
<SettingsCard
title="Subscribers List"
description={`Total subscribers: ${subscribersData?.count || 0}`}
>
<div className="space-y-4">
{/* Actions Bar */}
<div className="flex items-center justify-between gap-4">
<div className="relative flex-1 max-w-sm">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none" />
<Input
placeholder="Search by email..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-9"
/>
</div>
<div className="flex gap-2">
<Button onClick={exportSubscribers} variant="outline" size="sm">
<Download className="mr-2 h-4 w-4" />
Export CSV
</Button>
<Button variant="outline" size="sm">
<Mail className="mr-2 h-4 w-4" />
Send Campaign
</Button>
</div>
</div>
{/* Subscribers Table */}
{isLoading ? (
<div className="text-center py-8 text-muted-foreground">
Loading subscribers...
</div>
) : filteredSubscribers.length === 0 ? (
<div className="text-center py-8 text-muted-foreground">
{searchQuery ? 'No subscribers found matching your search' : 'No subscribers yet'}
</div>
) : (
<div className="border rounded-lg">
<Table>
<TableHeader>
<TableRow>
<TableHead>Email</TableHead>
<TableHead>Status</TableHead>
<TableHead>Subscribed Date</TableHead>
<TableHead>WP User</TableHead>
<TableHead className="text-right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredSubscribers.map((subscriber: any) => (
<TableRow key={subscriber.email}>
<TableCell className="font-medium">{subscriber.email}</TableCell>
<TableCell>
<span className="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800">
{subscriber.status || 'Active'}
</span>
</TableCell>
<TableCell className="text-muted-foreground">
{subscriber.subscribed_at
? new Date(subscriber.subscribed_at).toLocaleDateString()
: 'N/A'
}
</TableCell>
<TableCell>
{subscriber.user_id ? (
<span className="text-xs text-blue-600">Yes (ID: {subscriber.user_id})</span>
) : (
<span className="text-xs text-muted-foreground">No</span>
)}
</TableCell>
<TableCell className="text-right">
<Button
variant="ghost"
size="sm"
onClick={() => deleteSubscriber.mutate(subscriber.email)}
disabled={deleteSubscriber.isPending}
>
<Trash2 className="h-4 w-4 text-red-500" />
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
)}
</div>
</SettingsCard>
{/* Email Template Settings */}
<SettingsCard
title="Email Templates"
description="Customize newsletter email templates using the email builder"
>
<div className="space-y-4">
<div className="p-4 border rounded-lg bg-muted/50">
<h4 className="font-medium mb-2">Newsletter Welcome Email</h4>
<p className="text-sm text-muted-foreground mb-4">
Welcome email sent when someone subscribes to your newsletter
</p>
<Button
variant="outline"
size="sm"
onClick={() => navigate('/settings/notifications/customer/newsletter_welcome/edit')}
>
Edit Template
</Button>
</div>
<div className="p-4 border rounded-lg bg-muted/50">
<h4 className="font-medium mb-2">New Subscriber Notification (Admin)</h4>
<p className="text-sm text-muted-foreground mb-4">
Admin notification when someone subscribes to newsletter
</p>
<Button
variant="outline"
size="sm"
onClick={() => navigate('/settings/notifications/staff/newsletter_subscribed_admin/edit')}
>
Edit Template
</Button>
</div>
</div>
</SettingsCard>
</SettingsLayout>
);
}

View File

@@ -0,0 +1,5 @@
import { Navigate } from 'react-router-dom';
export default function Marketing() {
return <Navigate to="/marketing/newsletter" replace />;
}