Skip to content

Commit d33b0eb

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

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
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>

apps/dashboard/src/routes/protected-route.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { RedirectToSignIn, SignedIn, SignedOut } from '@clerk/clerk-react';
2-
import { ROUTES } from '@/utils/routes';
31
import { EnvironmentProvider } from '@/context/environment/environment-provider';
2+
import { RedirectToSignIn, SignedIn, SignedOut } from '@clerk/clerk-react';
43

54
export const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
65
return (

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

Lines changed: 17 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,31 @@ const actionZodSchema = z
3333
})
3434
.optional();
3535

36-
export const inAppControlZodSchema = z.object({
36+
const commonInAppProperties = {
3737
skip: skipZodSchema,
3838
disableOutputSanitization: z.boolean().optional(),
39-
subject: z.string().optional(),
40-
body: z.string(),
4139
avatar: z.string().regex(redirectUrlRegex).optional(),
4240
primaryAction: actionZodSchema,
4341
secondaryAction: actionZodSchema,
4442
data: z.object({}).catchall(z.unknown()).optional(),
4543
redirect: redirectZodSchema.optional(),
44+
};
45+
46+
const subjectRequiredSchema = z.object({
47+
subject: z.string(),
48+
body: z.string().optional(),
49+
...commonInAppProperties,
4650
});
4751

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

0 commit comments

Comments
 (0)