Skip to content

Commit 9921414

Browse files
committed
feat(api): Require either subject or body for in-app
1 parent da9336d commit 9921414

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-body.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const InAppBody = () => {
3131
onChange={field.onChange}
3232
variables={variables}
3333
isAllowedVariable={isAllowedVariable}
34-
autoFocus
3534
multiline
3635
/>
3736
</InputRoot>

apps/dashboard/src/components/workflow-editor/steps/in-app/in-app-subject.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const InAppSubject = () => {
3131
onChange={field.onChange}
3232
variables={variables}
3333
isAllowedVariable={isAllowedVariable}
34+
autoFocus
3435
/>
3536
</InputRoot>
3637
</FormControl>

libs/application-generic/src/schemas/control/in-app-control.schema.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const redirectUrlRegex =
2323

2424
const redirectZodSchema = z.object({
2525
url: z.string().regex(redirectUrlRegex),
26-
target: z.enum(['_self', '_blank', '_parent', '_top', '_unfencedTop']).default('_blank'),
26+
target: z.enum(['_self', '_blank', '_parent', '_top', '_unfencedTop']),
2727
});
2828

2929
const actionZodSchema = z
@@ -33,18 +33,32 @@ const actionZodSchema = z
3333
})
3434
.optional();
3535

36-
export const inAppControlZodSchema = z.object({
36+
// First, define the common properties that both schema variants will share
37+
const commonInAppProperties = {
3738
skip: skipZodSchema,
3839
disableOutputSanitization: z.boolean().optional(),
39-
subject: z.string().optional(),
40-
body: z.string(),
4140
avatar: z.string().regex(redirectUrlRegex).optional(),
4241
primaryAction: actionZodSchema,
4342
secondaryAction: actionZodSchema,
4443
data: z.object({}).catchall(z.unknown()).optional(),
4544
redirect: redirectZodSchema.optional(),
45+
};
46+
47+
const subjectRequiredSchema = z.object({
48+
subject: z.string(),
49+
body: z.string().optional(),
50+
...commonInAppProperties,
4651
});
4752

53+
const bodyRequiredSchema = z.object({
54+
subject: z.string().optional(),
55+
body: z.string(),
56+
...commonInAppProperties,
57+
});
58+
59+
// Write it this way because of how translation from zod to json schema works
60+
export const inAppControlZodSchema = z.union([subjectRequiredSchema, bodyRequiredSchema]);
61+
4862
export type InAppRedirectType = z.infer<typeof redirectZodSchema>;
4963
export type InAppActionType = z.infer<typeof actionZodSchema>;
5064
export type InAppControlType = z.infer<typeof inAppControlZodSchema>;

0 commit comments

Comments
 (0)