refactor: standardize task and recurrence type strings to lowercase across components and services

This commit is contained in:
JSC
2025-08-29 00:39:00 +02:00
parent 009780e64c
commit 4251057668
4 changed files with 52 additions and 40 deletions

View File

@@ -35,8 +35,8 @@ interface CreateTaskDialogProps {
onCancel: () => void
}
const TASK_TYPES: TaskType[] = ['CREDIT_RECHARGE', 'PLAY_SOUND', 'PLAY_PLAYLIST']
const RECURRENCE_TYPES: RecurrenceType[] = ['NONE', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY', 'CRON']
const TASK_TYPES: TaskType[] = ['credit_recharge', 'play_sound', 'play_playlist']
const RECURRENCE_TYPES: RecurrenceType[] = ['none', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'cron']
export function CreateTaskDialog({
open,
@@ -49,11 +49,11 @@ export function CreateTaskDialog({
const [formData, setFormData] = useState<CreateScheduledTaskRequest>({
name: '',
task_type: 'PLAY_SOUND',
task_type: 'play_sound',
scheduled_at: '',
timezone: timezone,
parameters: {},
recurrence_type: 'NONE',
recurrence_type: 'none',
cron_expression: null,
recurrence_count: null,
expires_at: null,
@@ -68,9 +68,21 @@ export function CreateTaskDialog({
// Validate parameters JSON
try {
const parameters = JSON.parse(parametersJson)
// Send the datetime as UTC to prevent backend timezone conversion
// The user's selected time should be stored exactly as entered
let scheduledAt = formData.scheduled_at
if (scheduledAt.length === 16) {
scheduledAt += ':00' // Add seconds if missing
}
// Add Z to indicate this is already UTC time, preventing backend conversion
const scheduledAtUTC = scheduledAt + 'Z'
onSubmit({
...formData,
parameters,
scheduled_at: scheduledAtUTC,
})
} catch {
setParametersError('Invalid JSON format')
@@ -95,11 +107,11 @@ export function CreateTaskDialog({
// Reset form
setFormData({
name: '',
task_type: 'PLAY_SOUND',
task_type: 'play_sound',
scheduled_at: '',
timezone: timezone,
parameters: {},
recurrence_type: 'NONE',
recurrence_type: 'none',
cron_expression: null,
recurrence_count: null,
expires_at: null,
@@ -114,7 +126,7 @@ export function CreateTaskDialog({
now.setMinutes(now.getMinutes() + 10) // Default to 10 minutes from now
// Format the time in the user's timezone
const formatter = new Intl.DateTimeFormat('fr-FR', {
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: timezone,
year: 'numeric',
month: '2-digit',
@@ -230,7 +242,7 @@ export function CreateTaskDialog({
</Select>
</div>
{formData.recurrence_type === 'CRON' && (
{formData.recurrence_type === 'cron' && (
<div className="space-y-2">
<Label htmlFor="cron_expression">Cron Expression</Label>
<Input
@@ -242,7 +254,7 @@ export function CreateTaskDialog({
</div>
)}
{formData.recurrence_type !== 'NONE' && formData.recurrence_type !== 'CRON' && (
{formData.recurrence_type !== 'none' && formData.recurrence_type !== 'cron' && (
<div className="space-y-2">
<Label htmlFor="recurrence_count">Max Executions</Label>
<Input

View File

@@ -33,8 +33,8 @@ interface SchedulersHeaderProps {
taskCount: number
}
const TASK_STATUSES: TaskStatus[] = ['PENDING', 'RUNNING', 'COMPLETED', 'FAILED', 'CANCELLED']
const TASK_TYPES: TaskType[] = ['CREDIT_RECHARGE', 'PLAY_SOUND', 'PLAY_PLAYLIST']
const TASK_STATUSES: TaskStatus[] = ['pending', 'running', 'completed', 'failed', 'cancelled']
const TASK_TYPES: TaskType[] = ['credit_recharge', 'play_sound', 'play_playlist']
export function SchedulersHeader({
searchQuery,

View File

@@ -102,7 +102,7 @@ export function SchedulersTable({ tasks, onTaskUpdated, onTaskDeleted }: Schedul
</div>
<p className="text-sm text-muted-foreground">
{getTaskTypeLabel(task.task_type)}
{task.recurrence_type !== 'NONE' && (
{task.recurrence_type !== 'none' && (
<span className="ml-2">
{getRecurrenceTypeLabel(task.recurrence_type)}
</span>
@@ -123,7 +123,7 @@ export function SchedulersTable({ tasks, onTaskUpdated, onTaskDeleted }: Schedul
<DropdownMenuContent align="end">
<DropdownMenuItem
onClick={() => handleToggleActive(task)}
disabled={task.status === 'COMPLETED' || task.status === 'CANCELLED'}
disabled={task.status === 'completed' || task.status === 'cancelled'}
>
{task.is_active ? (
<>
@@ -140,7 +140,7 @@ export function SchedulersTable({ tasks, onTaskUpdated, onTaskDeleted }: Schedul
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => handleCancelTask(task)}
disabled={task.status === 'COMPLETED' || task.status === 'CANCELLED'}
disabled={task.status === 'completed' || task.status === 'cancelled'}
className="text-destructive focus:text-destructive"
>
<Square className="h-4 w-4 mr-2" />
@@ -165,9 +165,9 @@ export function SchedulersTable({ tasks, onTaskUpdated, onTaskDeleted }: Schedul
<p className="font-medium">
{task.next_execution_at
? formatDate(task.next_execution_at)
: task.status === 'COMPLETED'
: task.status === 'completed'
? 'Completed'
: task.status === 'CANCELLED'
: task.status === 'cancelled'
? 'Cancelled'
: 'N/A'}
</p>