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