Skip to content

Commit 02fc57c

Browse files
committed
macro form fixes
1 parent cd0a357 commit 02fc57c

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

frontend/src/features/admin/macros/MacroForm.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
</FormItem>
2828
</FormField>
2929

30-
<FormField v-slot="{ componentField }" name="actions">
30+
<FormField
31+
v-slot="{ componentField }"
32+
name="actions"
33+
:validate-on-blur="false"
34+
:validate-on-change="false"
35+
>
3136
<FormItem>
3237
<FormLabel>
3338
{{ t('globals.terms.action', 2) }} ({{ t('globals.terms.optional', 1).toLowerCase() }})
@@ -71,7 +76,15 @@
7176
</FormItem>
7277
</FormField>
7378

74-
<FormField v-slot="{ componentField }" name="visibility">
79+
<FormField
80+
v-slot="{ componentField }"
81+
name="visibility"
82+
:validate-on-blur="false"
83+
:validate-on-change="false"
84+
:validate-on-input="false"
85+
:validate-on-mount="false"
86+
:validate-on-model-update="false"
87+
>
7588
<FormItem>
7689
<FormLabel>{{ t('globals.terms.visibility') }}</FormLabel>
7790
<FormControl>

frontend/src/features/admin/macros/formSchema.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as z from 'zod'
22
import { getTextFromHTML } from '@/utils/strings.js'
33

4-
const actionSchema = (t) => z.array(
4+
const actionSchema = () => z.array(
55
z.object({
6-
type: z.string().min(1, t('admin.macro.actionTypeRequired')),
7-
value: z.array(z.string().min(1, t('admin.macro.actionValueRequired'))),
6+
type: z.string().optional(),
7+
value: z.array(z.string()).optional(),
88
})
99
)
1010

@@ -35,19 +35,39 @@ export const createFormSchema = (t) => z.object({
3535
.refine(
3636
(data) => {
3737
// If visibility is 'team', team_id is required
38-
if (data.visibility === 'team' && !data.team_id) {
39-
return false
38+
if (data.visibility === 'team') {
39+
return !!data.team_id
4040
}
41+
return true
42+
},
43+
{
44+
message: t('globals.messages.required'),
45+
path: ['team_id'],
46+
}
47+
)
48+
.refine(
49+
(data) => {
4150
// If visibility is 'user', user_id is required
42-
if (data.visibility === 'user' && !data.user_id) {
43-
return false
51+
if (data.visibility === 'user') {
52+
return !!data.user_id
53+
}
54+
return true
55+
},
56+
{
57+
message: t('globals.messages.required'),
58+
path: ['user_id'],
59+
}
60+
).refine(
61+
(data) => {
62+
// if actions are present, all actions should have type and value defined.
63+
if (data.actions && data.actions.length > 0) {
64+
return data.actions.every(action => action.type?.length > 0 && action.value?.length > 0)
4465
}
45-
// Otherwise, validation passes
4666
return true
4767
},
4868
{
49-
message: t('admin.macro.teamOrUserRequired'),
69+
message: t('admin.macro.actionInvalid'),
5070
// Field path to highlight
51-
path: ['visibility'],
71+
path: ['actions'],
5272
}
5373
)

i18n/en.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,7 @@
392392
"admin.macro.messageContent": "Response to be sent when macro is used (optional)",
393393
"admin.macro.actions": "Actions (optional)",
394394
"admin.macro.messageOrActionRequired": "Either message content or actions are required",
395-
"admin.macro.actionTypeRequired": "Action type is required",
396-
"admin.macro.actionValueRequired": "Action value is required",
397-
"admin.macro.teamOrUserRequired": "Team or user is required",
395+
"admin.macro.actionInvalid": "Each action must have a type and a value",
398396
"admin.conversationStatus.name.description": "Set status name. Click save when you're done.",
399397
"admin.conversationStatus.deleteConfirmation": "This action cannot be undone. This will permanently delete this status.",
400398
"admin.inbox.name.description": "Name for your inbox.",

0 commit comments

Comments
 (0)