Replace hour-only select with HH:mm picker, show last run and send logs in Jalali, and display scheduled times as HH:mm in the table. Co-authored-by: Cursor <cursoragent@cursor.com>
105 lines
2.5 KiB
TypeScript
105 lines
2.5 KiB
TypeScript
export type AutomationTriggerType = 'schedule' | 'event' | 'price'
|
|
export type AutomationChannel = 'sms' | 'in_app'
|
|
export type AutomationConditionCr = 'and' | 'or'
|
|
|
|
export interface AutomationCondition {
|
|
cr?: AutomationConditionCr
|
|
field: string
|
|
op?: string | null
|
|
value?: unknown
|
|
}
|
|
|
|
export type AutomationAudienceMode = 'all' | 'filter'
|
|
export type AutomationPriceWindow = 'calendar_day' | 'from_last'
|
|
|
|
export interface AutomationTriggerConfig {
|
|
event?: string
|
|
delay_hours?: number
|
|
every_days?: number
|
|
step_toman?: number | string | null
|
|
direction?: 'up' | 'down' | 'both'
|
|
product_id?: number | null
|
|
price_window?: AutomationPriceWindow
|
|
}
|
|
|
|
export interface Automation {
|
|
id?: number
|
|
name: string
|
|
code?: string
|
|
is_active: boolean
|
|
starts_at?: string | null
|
|
ends_at?: string | null
|
|
sms_send_hour?: number | null
|
|
sms_send_minute?: number | null
|
|
in_app_send_hour?: number | null
|
|
in_app_send_minute?: number | null
|
|
trigger_type: AutomationTriggerType
|
|
trigger_config?: AutomationTriggerConfig
|
|
audience_mode?: AutomationAudienceMode
|
|
conditions?: AutomationCondition[]
|
|
channels: AutomationChannel[]
|
|
title: string
|
|
body: string
|
|
cooldown_hours?: number
|
|
max_sends?: number | null
|
|
sent_count?: number
|
|
failed_count?: number
|
|
}
|
|
|
|
export interface AutomationCatalogOption {
|
|
key: string | number
|
|
name: string
|
|
}
|
|
|
|
export interface AutomationFieldInput {
|
|
key: string
|
|
type: 'number' | 'select' | 'operator'
|
|
label: string
|
|
options?: AutomationCatalogOption[]
|
|
}
|
|
|
|
export interface AutomationField {
|
|
key: string
|
|
group: string
|
|
name: string
|
|
inputs: AutomationFieldInput[]
|
|
}
|
|
|
|
export interface AutomationCatalog {
|
|
triggers: AutomationCatalogOption[]
|
|
events: AutomationCatalogOption[]
|
|
channels: AutomationCatalogOption[]
|
|
operators: AutomationCatalogOption[]
|
|
fields: AutomationField[]
|
|
products: Array<{ id: number; name: string }>
|
|
hours: AutomationCatalogOption[]
|
|
price_windows?: AutomationCatalogOption[]
|
|
audience_modes?: AutomationCatalogOption[]
|
|
}
|
|
|
|
export function emptyAutomation(): Automation {
|
|
return {
|
|
name: '',
|
|
title: '',
|
|
body: '',
|
|
is_active: true,
|
|
trigger_type: 'schedule',
|
|
audience_mode: 'all',
|
|
trigger_config: {
|
|
delay_hours: 0,
|
|
every_days: 1,
|
|
direction: 'both',
|
|
price_window: 'calendar_day',
|
|
},
|
|
conditions: [],
|
|
channels: ['sms'],
|
|
sms_send_hour: 10,
|
|
sms_send_minute: 0,
|
|
in_app_send_hour: 10,
|
|
in_app_send_minute: 0,
|
|
cooldown_hours: 24,
|
|
starts_at: null,
|
|
ends_at: null,
|
|
}
|
|
}
|