* refactor(web): centralize data table implementation - route all TanStack table setup through a shared data-table hook to remove repeated state and row model wiring. - move table rendering, static table wrappers, empty states, and primitive exports behind the data-table module. - update feature tables and configuration editors to share the same table UX while preserving their existing workflows. * refactor(web): trim data table public API - remove unused data-table exports and dead static table helper types. - keep internal table header, skeleton, empty state, and faceted filter helpers private to the data-table module. - route feature imports through the data-table barrel to avoid subpath coupling. * refactor(web): unify table rendering components - centralize static table headers, bodies, empty states, and shared class names behind the data-table package. - migrate settings, pricing, channel, key, subscription, and model tables to the shared table APIs. - remove data-table exports for low-level table primitives so feature code uses one supported abstraction. * perf(web): keep list tables fixed within page content - make shared data table pages fill available height and scroll row data inside the table body. - add a fixed content layout mode so selected list pages avoid page-level scrolling. - apply the fixed table behavior to keys, logs, channels, models, users, redemptions, and subscriptions. * perf(web): refine table pagination controls - show total row counts instead of redundant page range text. - tighten visible page buttons so pagination fits constrained table widths. - align pagination controls and tune text hierarchy for clearer scanning. * perf(web): stabilize model pricing table columns - keep model pricing columns at fixed widths so headers do not collapse in narrow layouts. - truncate long model names and pricing summaries within their cells instead of squeezing adjacent columns. * refactor(web): simplify data table rendering internals - split table body rendering into focused helpers for loading, empty, and row states. - extract static table row and cell class resolution to reduce branching in the main component. - reuse a single pagination page-size option list to avoid duplicated constants. * perf(pricing): reduce dynamic pricing table render work - reuse dynamic pricing field metadata instead of rebuilding it inside table columns. - precompute formatted dynamic prices per tier and group to avoid repeated entry mapping for each cell. - simplify select option construction in related dialogs while preserving the same choices. * refactor(web): streamline pricing table rendering - reuse translated endpoint select options between trigger data and menu items. - precompute dynamic pricing maps per group so table cells only resolve formatted values. - add local dynamic pricing type aliases to keep helper signatures readable. * refactor(web): merge pricing table imports * refactor(web): merge upstream ratio table imports * refactor(web): merge channel selector table imports * refactor(web): simplify tiered pricing select items * refactor(web): reuse model ratio row state * refactor(web): rely on table view row defaults * refactor(web): reuse pagination state values * refactor(web): hoist pagination size select items * refactor(web): clarify static table body rows * refactor(web): extract table page pagination rendering * fix(web): remove direct hast type dependency - rely on Shiki transformer contextual typing for line nodes. - allow frontend typecheck to pass without an undeclared hast package. * refactor(web): trim data table hook return API - return only the TanStack table instance from useDataTable. - keep internal state handling private because callers do not consume it directly. * refactor(web): keep static table empty row private - stop exporting the internal StaticDataTableEmptyRow helper. - keep the public static table API focused on the table component and column type. * refactor(web): hide data table view props from barrel * refactor(web): remove stale long text lint override * fix(web): keep pinned table columns opaque - apply pinned column background classes after custom column classes. - use an opaque hover background so scrolled content cannot show through fixed cells. * refactor(data-table): organize shared table components - group table primitives, page composition, toolbar controls, static tables, and hooks by responsibility. - split shared view types, row rendering, header rendering, and pinned-column styling out of the main table view. - keep the public data-table barrel stable while documenting the new ownership boundaries. * fix(web): stabilize split table column sizing - derive default colgroup widths from visible columns when split headers or header sizing are enabled. - apply a fixed table layout with computed minimum width so header and body columns stay aligned. - keep split-header containers from leaking horizontal overflow and avoid extra pinned-column borders. * fix(web): set stable table utility column widths - assign fixed widths to selection columns so shared colgroup sizing keeps checkbox cells compact. - size id columns in redemption and user tables to keep split headers aligned with body rows. * fix(web): align model metadata icon cells - render compact provider avatars in the metadata icon column instead of wide wordmarks. - position icons in a fixed-size wrapper so they line up with the existing icon header alignment. * fix(status-badge): hide status dot by default * fix(web): prevent user invite info overlap - give the invite info and created-at columns explicit widths so table sizing reserves enough space. - allow invite badges to wrap within the cell instead of spilling into adjacent columns. * perf(data-table): cache pinned column class resolution - reuse the pinned column lookup while table props stay stable to reduce repeated per-render work. - share the resolved column class handler across unified and split-header table layouts. - localize page-number screen reader labels so pagination remains accessible in every locale. * refactor(data-table): tighten static table modes - make StaticDataTable distinguish data-driven and children-only usage through explicit prop shapes. - remove unsupported columns-without-data fallback after confirming no repository callers rely on it. - default manual table modes away from unused local row models to reduce repeated table work. * fix(data-table): make pinned edit column opaque - use an opaque muted background for the active action column so sticky cells do not reveal scrolled content underneath. * fix(data-table): prevent narrow column overlap - apply stable header sizing to remaining desktop data table pages so constrained layouts scroll instead of compressing cells. - add explicit widths for key, quota, badge, and timestamp columns that contain fixed-format content. - constrain masked values and timestamp cells with truncation to keep content inside its assigned column. * fix(table): align table cell content with headers - remove extra inline padding from masked table text buttons so values start at the cell edge. - tag status badges and offset leading badges inside table cells to match header text alignment. * fix(table): prevent admin list column overflow - widen redemption and subscription table columns so masked codes, timestamps, and localized headers fit. - localize subscription ID headers and add Received amount translations across supported locales. * fix(provider-badge): unify provider icon spacing - add a shared provider badge component for icon and status label layout. - reuse it in channel type and model vendor columns so OpenAI icons align consistently.
620 lines
19 KiB
TypeScript
Vendored
620 lines
19 KiB
TypeScript
Vendored
/*
|
|
Copyright (C) 2023-2026 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
import * as z from 'zod'
|
|
import { useForm } from 'react-hook-form'
|
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { Plus, Edit, Trash2, Save } from 'lucide-react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { toast } from 'sonner'
|
|
import dayjs from '@/lib/dayjs'
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from '@/components/ui/alert-dialog'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Checkbox } from '@/components/ui/checkbox'
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormDescription,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from '@/components/ui/form'
|
|
import { Input } from '@/components/ui/input'
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectGroup,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from '@/components/ui/select'
|
|
import { Textarea } from '@/components/ui/textarea'
|
|
import { StaticDataTable } from '@/components/data-table'
|
|
import { DateTimePicker } from '@/components/datetime-picker'
|
|
import { Dialog } from '@/components/dialog'
|
|
import { StatusBadge } from '@/components/status-badge'
|
|
import { SettingsSwitchField } from '../components/settings-form-layout'
|
|
import { SettingsSection } from '../components/settings-section'
|
|
import { useUpdateOption } from '../hooks/use-update-option'
|
|
|
|
type Announcement = {
|
|
id: number
|
|
content: string
|
|
publishDate: string
|
|
type: 'default' | 'ongoing' | 'success' | 'warning' | 'error'
|
|
extra?: string
|
|
}
|
|
|
|
type AnnouncementsSectionProps = {
|
|
enabled: boolean
|
|
data: string
|
|
}
|
|
|
|
const announcementSchema = z.object({
|
|
content: z
|
|
.string()
|
|
.min(1, 'Content is required')
|
|
.max(500, 'Content must be less than 500 characters'),
|
|
publishDate: z.string().min(1, 'Publish date is required'),
|
|
type: z.enum(['default', 'ongoing', 'success', 'warning', 'error']),
|
|
extra: z
|
|
.string()
|
|
.max(100, 'Extra must be less than 100 characters')
|
|
.optional(),
|
|
})
|
|
|
|
type AnnouncementFormValues = z.infer<typeof announcementSchema>
|
|
|
|
const ANNOUNCEMENT_FORM_ID = 'announcement-form'
|
|
|
|
const typeOptions = [
|
|
{
|
|
value: 'default',
|
|
label: 'Default',
|
|
color: 'bg-gray-500',
|
|
badgeVariant: 'neutral' as const,
|
|
},
|
|
{
|
|
value: 'ongoing',
|
|
label: 'Ongoing',
|
|
color: 'bg-blue-500',
|
|
badgeVariant: 'info' as const,
|
|
},
|
|
{
|
|
value: 'success',
|
|
label: 'Success',
|
|
color: 'bg-green-500',
|
|
badgeVariant: 'success' as const,
|
|
},
|
|
{
|
|
value: 'warning',
|
|
label: 'Warning',
|
|
color: 'bg-orange-500',
|
|
badgeVariant: 'warning' as const,
|
|
},
|
|
{
|
|
value: 'error',
|
|
label: 'Error',
|
|
color: 'bg-red-500',
|
|
badgeVariant: 'danger' as const,
|
|
},
|
|
]
|
|
|
|
export function AnnouncementsSection({
|
|
enabled,
|
|
data,
|
|
}: AnnouncementsSectionProps) {
|
|
const { t } = useTranslation()
|
|
const updateOption = useUpdateOption()
|
|
const [announcements, setAnnouncements] = useState<Announcement[]>([])
|
|
const [isEnabled, setIsEnabled] = useState(enabled)
|
|
const [hasChanges, setHasChanges] = useState(false)
|
|
const [selectedIds, setSelectedIds] = useState<number[]>([])
|
|
const [showDialog, setShowDialog] = useState(false)
|
|
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
|
const [editingAnnouncement, setEditingAnnouncement] =
|
|
useState<Announcement | null>(null)
|
|
const [deleteTarget, setDeleteTarget] = useState<'single' | 'batch'>('single')
|
|
|
|
const form = useForm<AnnouncementFormValues>({
|
|
resolver: zodResolver(announcementSchema),
|
|
defaultValues: {
|
|
content: '',
|
|
publishDate: new Date().toISOString(),
|
|
type: 'default',
|
|
extra: '',
|
|
},
|
|
})
|
|
|
|
useEffect(() => {
|
|
try {
|
|
const parsed = JSON.parse(data || '[]')
|
|
if (Array.isArray(parsed)) {
|
|
setAnnouncements(
|
|
parsed.map((item, idx) => ({
|
|
...item,
|
|
id: item.id || idx + 1,
|
|
}))
|
|
)
|
|
}
|
|
} catch {
|
|
setAnnouncements([])
|
|
}
|
|
}, [data])
|
|
|
|
useEffect(() => {
|
|
setIsEnabled(enabled)
|
|
}, [enabled])
|
|
|
|
const handleToggleEnabled = async (checked: boolean) => {
|
|
try {
|
|
await updateOption.mutateAsync({
|
|
key: 'console_setting.announcements_enabled',
|
|
value: checked,
|
|
})
|
|
setIsEnabled(checked)
|
|
toast.success(t('Setting saved'))
|
|
} catch {
|
|
toast.error(t('Failed to update setting'))
|
|
}
|
|
}
|
|
|
|
const handleAdd = () => {
|
|
setEditingAnnouncement(null)
|
|
form.reset({
|
|
content: '',
|
|
publishDate: new Date().toISOString(),
|
|
type: 'default',
|
|
extra: '',
|
|
})
|
|
setShowDialog(true)
|
|
}
|
|
|
|
const handleEdit = (announcement: Announcement) => {
|
|
setEditingAnnouncement(announcement)
|
|
form.reset({
|
|
content: announcement.content,
|
|
publishDate: announcement.publishDate,
|
|
type: announcement.type,
|
|
extra: announcement.extra || '',
|
|
})
|
|
setShowDialog(true)
|
|
}
|
|
|
|
const handleDelete = (announcement: Announcement) => {
|
|
setEditingAnnouncement(announcement)
|
|
setDeleteTarget('single')
|
|
setShowDeleteDialog(true)
|
|
}
|
|
|
|
const handleBatchDelete = () => {
|
|
if (selectedIds.length === 0) {
|
|
toast.error(t('Please select items to delete'))
|
|
return
|
|
}
|
|
setDeleteTarget('batch')
|
|
setShowDeleteDialog(true)
|
|
}
|
|
|
|
const confirmDelete = () => {
|
|
if (deleteTarget === 'single' && editingAnnouncement) {
|
|
setAnnouncements((prev) =>
|
|
prev.filter((item) => item.id !== editingAnnouncement.id)
|
|
)
|
|
setHasChanges(true)
|
|
toast.success(t('Announcement deleted. Click "Save Settings" to apply.'))
|
|
} else if (deleteTarget === 'batch') {
|
|
setAnnouncements((prev) =>
|
|
prev.filter((item) => !selectedIds.includes(item.id))
|
|
)
|
|
setSelectedIds([])
|
|
setHasChanges(true)
|
|
toast.success(
|
|
t('{{count}} announcements deleted. Click "Save Settings" to apply.', {
|
|
count: selectedIds.length,
|
|
})
|
|
)
|
|
}
|
|
setShowDeleteDialog(false)
|
|
setEditingAnnouncement(null)
|
|
}
|
|
|
|
const handleSubmitForm = (values: AnnouncementFormValues) => {
|
|
if (editingAnnouncement) {
|
|
setAnnouncements((prev) =>
|
|
prev.map((item) =>
|
|
item.id === editingAnnouncement.id ? { ...item, ...values } : item
|
|
)
|
|
)
|
|
toast.success(t('Announcement updated. Click "Save Settings" to apply.'))
|
|
} else {
|
|
const newId = Math.max(...announcements.map((item) => item.id), 0) + 1
|
|
setAnnouncements((prev) => [...prev, { id: newId, ...values }])
|
|
toast.success(t('Announcement added. Click "Save Settings" to apply.'))
|
|
}
|
|
setHasChanges(true)
|
|
setShowDialog(false)
|
|
}
|
|
|
|
const handleSaveAll = async () => {
|
|
try {
|
|
await updateOption.mutateAsync({
|
|
key: 'console_setting.announcements',
|
|
value: JSON.stringify(announcements),
|
|
})
|
|
setHasChanges(false)
|
|
toast.success(t('Announcements saved successfully'))
|
|
} catch {
|
|
toast.error(t('Failed to save announcements'))
|
|
}
|
|
}
|
|
|
|
const toggleSelectAll = (checked: boolean) => {
|
|
setSelectedIds(checked ? announcements.map((item) => item.id) : [])
|
|
}
|
|
|
|
const toggleSelectOne = (id: number, checked: boolean) => {
|
|
setSelectedIds((prev) =>
|
|
checked ? [...prev, id] : prev.filter((item) => item !== id)
|
|
)
|
|
}
|
|
|
|
const sortedAnnouncements = useMemo(() => {
|
|
return [...announcements].sort((a, b) => {
|
|
return (
|
|
new Date(b.publishDate).getTime() - new Date(a.publishDate).getTime()
|
|
)
|
|
})
|
|
}, [announcements])
|
|
|
|
const getRelativeTime = (date: string) => {
|
|
const now = new Date()
|
|
const past = new Date(date)
|
|
const diffMs = now.getTime() - past.getTime()
|
|
const diffMins = Math.floor(diffMs / 60000)
|
|
const diffHours = Math.floor(diffMins / 60)
|
|
const diffDays = Math.floor(diffHours / 24)
|
|
|
|
if (diffMins < 60) return `${diffMins}m ago`
|
|
if (diffHours < 24) return `${diffHours}h ago`
|
|
return `${diffDays}d ago`
|
|
}
|
|
|
|
return (
|
|
<SettingsSection title={t('Announcements')}>
|
|
<div className='space-y-4'>
|
|
<div className='flex flex-wrap items-center justify-between gap-2'>
|
|
<div className='flex flex-wrap items-center gap-2'>
|
|
<Button onClick={handleAdd} size='sm'>
|
|
<Plus className='mr-2 h-4 w-4' />
|
|
{t('Add Announcement')}
|
|
</Button>
|
|
<Button
|
|
onClick={handleBatchDelete}
|
|
size='sm'
|
|
variant='destructive'
|
|
disabled={selectedIds.length === 0}
|
|
>
|
|
<Trash2 className='mr-2 h-4 w-4' />
|
|
{t('Delete (')}
|
|
{selectedIds.length})
|
|
</Button>
|
|
<Button
|
|
onClick={handleSaveAll}
|
|
size='sm'
|
|
variant='secondary'
|
|
disabled={!hasChanges || updateOption.isPending}
|
|
>
|
|
<Save className='mr-2 h-4 w-4' />
|
|
{updateOption.isPending ? t('Saving...') : t('Save Settings')}
|
|
</Button>
|
|
</div>
|
|
<SettingsSwitchField
|
|
checked={isEnabled}
|
|
onCheckedChange={handleToggleEnabled}
|
|
label={t('Enabled')}
|
|
className='border-b-0 py-0'
|
|
/>
|
|
</div>
|
|
|
|
<StaticDataTable
|
|
data={sortedAnnouncements}
|
|
getRowKey={(announcement) => announcement.id}
|
|
emptyContent={t(
|
|
'No announcements yet. Click "Add Announcement" to create one.'
|
|
)}
|
|
columns={[
|
|
{
|
|
id: 'select',
|
|
header: (
|
|
<Checkbox
|
|
checked={
|
|
selectedIds.length === announcements.length &&
|
|
announcements.length > 0
|
|
}
|
|
onCheckedChange={toggleSelectAll}
|
|
/>
|
|
),
|
|
className: 'w-12',
|
|
cell: (announcement) => (
|
|
<Checkbox
|
|
checked={selectedIds.includes(announcement.id)}
|
|
onCheckedChange={(checked) =>
|
|
toggleSelectOne(announcement.id, checked as boolean)
|
|
}
|
|
/>
|
|
),
|
|
},
|
|
{
|
|
id: 'content',
|
|
header: t('Content'),
|
|
cellClassName: 'max-w-xs truncate',
|
|
cell: (announcement) => announcement.content,
|
|
},
|
|
{
|
|
id: 'publish-date',
|
|
header: t('Publish Date'),
|
|
cell: (announcement) => (
|
|
<div className='flex flex-col gap-1'>
|
|
<span className='text-sm font-medium'>
|
|
{getRelativeTime(announcement.publishDate)}
|
|
</span>
|
|
<span className='text-muted-foreground text-xs'>
|
|
{dayjs(announcement.publishDate).format(
|
|
'YYYY-MM-DD HH:mm:ss'
|
|
)}
|
|
</span>
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
id: 'type',
|
|
header: t('Type'),
|
|
cell: (announcement) => (
|
|
<StatusBadge
|
|
label={
|
|
typeOptions.find((opt) => opt.value === announcement.type)
|
|
?.label
|
|
}
|
|
variant={
|
|
typeOptions.find((opt) => opt.value === announcement.type)
|
|
?.badgeVariant ?? 'neutral'
|
|
}
|
|
copyable={false}
|
|
/>
|
|
),
|
|
},
|
|
{
|
|
id: 'extra',
|
|
header: t('Extra'),
|
|
cellClassName: 'text-muted-foreground max-w-xs truncate',
|
|
cell: (announcement) => announcement.extra || '-',
|
|
},
|
|
{
|
|
id: 'actions',
|
|
header: t('Actions'),
|
|
className: 'w-32',
|
|
cell: (announcement) => (
|
|
<div className='flex gap-2'>
|
|
<Button
|
|
onClick={() => handleEdit(announcement)}
|
|
size='sm'
|
|
variant='ghost'
|
|
>
|
|
<Edit className='h-4 w-4' />
|
|
</Button>
|
|
<Button
|
|
onClick={() => handleDelete(announcement)}
|
|
size='sm'
|
|
variant='ghost'
|
|
>
|
|
<Trash2 className='h-4 w-4' />
|
|
</Button>
|
|
</div>
|
|
),
|
|
},
|
|
]}
|
|
/>
|
|
</div>
|
|
|
|
<Dialog
|
|
open={showDialog}
|
|
onOpenChange={setShowDialog}
|
|
title={
|
|
editingAnnouncement ? t('Edit Announcement') : t('Add Announcement')
|
|
}
|
|
description={t(
|
|
'Create or update system announcements for the dashboard'
|
|
)}
|
|
contentClassName='max-w-2xl'
|
|
contentHeight='auto'
|
|
bodyClassName='space-y-4'
|
|
footer={
|
|
<>
|
|
<Button
|
|
type='button'
|
|
variant='outline'
|
|
onClick={() => setShowDialog(false)}
|
|
>
|
|
{t('Cancel')}
|
|
</Button>
|
|
<Button type='submit' form={ANNOUNCEMENT_FORM_ID}>
|
|
{editingAnnouncement ? t('Update') : t('Add')}
|
|
</Button>
|
|
</>
|
|
}
|
|
>
|
|
<Form {...form}>
|
|
<form
|
|
id={ANNOUNCEMENT_FORM_ID}
|
|
onSubmit={form.handleSubmit(handleSubmitForm)}
|
|
className='space-y-4'
|
|
>
|
|
<FormField
|
|
control={form.control}
|
|
name='content'
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t('Content')}</FormLabel>
|
|
<FormControl>
|
|
<Textarea
|
|
placeholder={t(
|
|
'Enter announcement content (supports Markdown/HTML)'
|
|
)}
|
|
rows={4}
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
<FormDescription>
|
|
{t('Maximum 500 characters. Supports Markdown and HTML.')}
|
|
</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name='publishDate'
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t('Publish Date')}</FormLabel>
|
|
<FormControl>
|
|
<DateTimePicker
|
|
value={field.value ? new Date(field.value) : undefined}
|
|
onChange={(date) =>
|
|
field.onChange(date ? date.toISOString() : '')
|
|
}
|
|
placeholder={t('Select publish date')}
|
|
/>
|
|
</FormControl>
|
|
<FormDescription>
|
|
{t(
|
|
'Date and time when this announcement should be displayed'
|
|
)}
|
|
</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name='type'
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t('Type')}</FormLabel>
|
|
<Select
|
|
items={[
|
|
...typeOptions.map((option) => ({
|
|
value: option.value,
|
|
label: (
|
|
<div className='flex items-center gap-2'>
|
|
<div
|
|
className={`h-3 w-3 rounded-full ${option.color}`}
|
|
/>
|
|
{option.label}
|
|
</div>
|
|
),
|
|
})),
|
|
]}
|
|
onValueChange={field.onChange}
|
|
value={field.value}
|
|
>
|
|
<FormControl>
|
|
<SelectTrigger>
|
|
<SelectValue
|
|
placeholder={t('Select announcement type')}
|
|
/>
|
|
</SelectTrigger>
|
|
</FormControl>
|
|
<SelectContent alignItemWithTrigger={false}>
|
|
<SelectGroup>
|
|
{typeOptions.map((option) => (
|
|
<SelectItem key={option.value} value={option.value}>
|
|
<div className='flex items-center gap-2'>
|
|
<div
|
|
className={`h-3 w-3 rounded-full ${option.color}`}
|
|
/>
|
|
{option.label}
|
|
</div>
|
|
</SelectItem>
|
|
))}
|
|
</SelectGroup>
|
|
</SelectContent>
|
|
</Select>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name='extra'
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>{t('Extra Notes (Optional)')}</FormLabel>
|
|
<FormControl>
|
|
<Input
|
|
placeholder={t('Additional information')}
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
<FormDescription>
|
|
{t(
|
|
'Optional supplementary information (max 100 characters)'
|
|
)}
|
|
</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</form>
|
|
</Form>
|
|
</Dialog>
|
|
|
|
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{t('Are you sure?')}</AlertDialogTitle>
|
|
<AlertDialogDescription>
|
|
{deleteTarget === 'single'
|
|
? 'This announcement will be removed from the list.'
|
|
: `${selectedIds.length} announcements will be removed from the list.`}
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>{t('Cancel')}</AlertDialogCancel>
|
|
<AlertDialogAction onClick={confirmDelete}>
|
|
{t('Delete')}
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</SettingsSection>
|
|
)
|
|
}
|