Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

save the JSON values

Kiran Kea9f54ea34cd
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index b110c5bdd6..20cbaebd1a 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -41,6 +41,21 @@ export const DomainSchema = z.object({
"The URL to redirect to when a link under this domain doesn't exist.",
)
.openapi({ example: "https://acme.com/not-found" }),
+ assetLinks: z
+ .any()
+ .nullable()
+ .transform((v) => (v ? JSON.stringify(v) : null))
+ .describe(
+ "assetLinks.json configuration file (for deep link support on Android).",
+ ),
+ appleAppSiteAssociation: z
+ .any()
+ .nullable()
+ .transform((v) => (v ? JSON.stringify(v) : null))
+ .describe(
+ "apple-app-site-association configuration file (for deep link support on iOS).",
+ ),
+
logo: z.string().nullable().describe("The logo of the domain."),
createdAt: z.date().describe("The date the domain was created."),
updatedAt: z.date().describe("The date the domain was last updated."),
@@ -86,6 +101,19 @@ export const getDefaultDomainsQuerySchema = getDomainsQuerySchema.pick({
search: true,
});
+const validateJSON = (v: any) => {
+ if (!v) {
+ return true;
+ }
+
+ try {
+ JSON.parse(v);
+ return true;
+ } catch (error) {
+ return false;
+ }
+};
+
export const createDomainBodySchema = z.object({
slug: z
.string({ required_error: "slug is required" })
@@ -132,12 +160,16 @@ export const createDomainBodySchema = z.object({
assetLinks: z
.string()
.nullish()
+ .default(null)
+ .refine((v) => validateJSON(v))
.describe(
"assetLinks.json configuration file (for deep link support on Android).",
),
appleAppSiteAssociation: z
.string()
.nullish()
+ .default(null)
+ .refine((v) => validateJSON(v))
.describe(
"apple-app-site-association configuration file (for deep link support on iOS).",
),
diff --git a/apps/web/ui/domains/add-edit-domain-form.tsx b/apps/web/ui/domains/add-edit-domain-form.tsx
index 3a33eb774a..5cfdf79720 100644
--- a/apps/web/ui/domains/add-edit-domain-form.tsx
+++ b/apps/web/ui/domains/add-edit-domain-form.tsx
@@ -428,86 +428,62 @@ export function AddEditDomainForm({
</button>
</div>
- <AnimatedSizeContainer height className="mt-4 flex flex-col space-y-4">
- {showAdvancedOptions &&
- ADVANCED_OPTIONS.map(
- ({ id, title, description, icon: Icon, proFeature }) => (
- <div key={id} className="flex flex-col space-y-3">
- <div className="flex items-center justify-between">
- <div className="flex items-center gap-3">
- <div className="hidden rounded-lg border border-neutral-200 bg-white p-2 sm:block">
- <Icon className="size-5 text-neutral-500" />
- </div>
- <div>
- <div className="flex items-center gap-2">
- <h2 className="text-sm font-medium text-neutral-900">
- {title}
- </h2>
- {proFeature && plan === "free" && (
- <Badge className="flex items-center space-x-1 bg-white">
- <Crown size={12} />
- <p className="uppercase">Pro</p>
- </Badge>
- )}
+ <AnimatedSizeContainer height className="mt-6">
+ <div className="flex flex-col space-y-4">
+ {showAdvancedOptions &&
+ ADVANCED_OPTIONS.map(
+ ({ id, title, description, icon: Icon, proFeature }) => (
+ <div key={id} className="flex flex-col space-y-3">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-3">
+ <div className="hidden rounded-lg border border-neutral-200 bg-white p-2 sm:block">
+ <Icon className="size-5 text-neutral-500" />
+ </div>
+ <div>
+ <div className="flex items-center gap-2">
+ <h2 className="text-sm font-medium text-neutral-900">
+ {title}
+ </h2>
+ {proFeature && plan === "free" && (
+ <Badge className="flex items-center space-x-1 bg-white">
+ <Crown size={12} />
+ <p className="uppercase">Pro</p>
+ </Badge>
+ )}
+ </div>
+ <p className="text-sm text-neutral-500">
+ {description}
+ </p>
</div>
- <p className="text-sm text-neutral-500">
- {description}
- </p>
</div>
+
+ <Switch
+ checked={!!watch(id)}
+ fn={(checked) => {
+ if (checked) {
+ setValue(id, " ", { shouldDirty: true });
+ } else {
+ setValue(id, null, { shouldDirty: true });
+ }
+ }}
+ disabled={isSubmitting}
+ />
</div>
- <Switch
- checked={!!watch(id)}
- fn={(checked) => {
- if (checked) {
- const defaultConfig =
- id === "appleAppSiteAssociation"
- ? {
- applinks: {
- apps: [],
- details: [
- {
- appID: "ZFQFH27SSZ.yuca.scanner",
- paths: ["NOT /_/*", "/*"],
- },
- ],
- },
- }
- : {
- target: {
- namespace: "android_app",
- package_name: "io.yuka.android",
- sha256_cert_fingerprints: [
- "A7:E3:C4:A6:12:68:01:86:93:7B:02:E7:B8:95:74:D5:FD:62:79:8B:8C:B6:68:97:39:92:FA:89:F6:19:8F:CB",
- ],
- },
- relation: [
- "delegate_permission/common.handle_all_urls",
- ],
- };
- setValue(
- id,
- JSON.stringify(defaultConfig, null, 2),
- { shouldDirty: true },
- );
- } else {
- setValue(id, "", { shouldDirty: true });
- }
- }}
- disabled={isSubmitting}
- />
+ {!!watch(id) && (
+ <div className="rounded-md border border-neutral-200 bg-white">
+ <textarea
+ {...register(id)}
+ className="w-full resize-none rounded-md border-0 bg-transparent px-3 py-2 font-mono text-xs text-neutral-700 focus:outline-none focus:ring-0"
+ rows={3}
+ spellCheck={false}
+ />
+ </div>
+ )}
</div>
-
- {!!watch(id) && (
- <div className="rounded-md border border-neutral-200 bg-white p-3">
- <pre className="whitespace-pre-wrap font-mono text-xs text-neutral-700">
- {watch(id)}
- </pre>
- </div>
- )}
- </div>
- ),
- )}
+ ),
+ )}
+ </div>
</AnimatedSizeContainer>
</div>
</>