From 560b80a9f70f673997a15d3dce1cc9716c06930a Mon Sep 17 00:00:00 2001
From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com>
Date: Wed, 2 Oct 2024 10:13:46 +0200
Subject: [PATCH] feat(connect): support for domain suffix, hidden fields,
default value (#2797)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## Describe your changes
Fixes
https://linear.app/nango/issue/NAN-1834/support-for-domain-suffix-hidden-fields-default-value
- Support for domain suffix
- Support for hidden fields
For fields that are going to be shown in the UI (because they have a
default value). Will be useful when I get session token values
- Support for default value
It's useful for some providers with static values (e.g: Freshdesk has a
static password because they choose to use basic auth with an api key 🤦🏻
). Will also be useful when I get session token values
- Backfill domain suffix
- Add some warnings in `validate.ts` so I can track progress
--
---
docs-v2/integrations/all/algolia/connect.mdx | 1 -
.../connect-ui/src/components/CustomInput.tsx | 33 +++++
packages/connect-ui/src/views/Go.tsx | 58 ++++----
packages/shared/providers.yaml | 138 ++++++++++++++----
packages/types/lib/providers/provider.ts | 3 +
scripts/validation/providers/schema.json | 12 ++
scripts/validation/providers/validate.ts | 15 +-
7 files changed, 201 insertions(+), 59 deletions(-)
create mode 100644 packages/connect-ui/src/components/CustomInput.tsx
diff --git a/docs-v2/integrations/all/algolia/connect.mdx b/docs-v2/integrations/all/algolia/connect.mdx
index 750e34433ae..2278d22b966 100644
--- a/docs-v2/integrations/all/algolia/connect.mdx
+++ b/docs-v2/integrations/all/algolia/connect.mdx
@@ -46,4 +46,3 @@ Once you have both the **Application ID** and **Admin API Key**:
You are now connected to Algolia.
-
diff --git a/packages/connect-ui/src/components/CustomInput.tsx b/packages/connect-ui/src/components/CustomInput.tsx
new file mode 100644
index 00000000000..aceb26801a9
--- /dev/null
+++ b/packages/connect-ui/src/components/CustomInput.tsx
@@ -0,0 +1,33 @@
+import * as React from 'react';
+
+import { cn } from '@/lib/utils';
+
+export type InputProps = React.InputHTMLAttributes & {
+ prefix?: React.ReactNode;
+ suffix?: React.ReactNode;
+ fluid?: boolean;
+};
+
+// until shadcn provide before/after it's going to be custom
+const CustomInput = React.forwardRef(({ className, type, prefix, suffix, fluid, ...props }, ref) => {
+ return (
+
+ {prefix &&
{prefix}
}
+
+ {suffix &&
{suffix}
}
+
+ );
+});
+CustomInput.displayName = 'Input';
+
+export { CustomInput };
diff --git a/packages/connect-ui/src/views/Go.tsx b/packages/connect-ui/src/views/Go.tsx
index 9485abd35f2..2150e139e32 100644
--- a/packages/connect-ui/src/views/Go.tsx
+++ b/packages/connect-ui/src/views/Go.tsx
@@ -9,14 +9,14 @@ import { z } from 'zod';
import type { AuthResult } from '@nangohq/frontend';
import type { AuthModeType } from '@nangohq/types';
+import { CustomInput } from '@/components/CustomInput';
import { Layout } from '@/components/Layout';
import { Button } from '@/components/ui/button';
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
-import { Input } from '@/components/ui/input';
import { triggerClose, triggerConnection } from '@/lib/events';
import { nango } from '@/lib/nango';
import { useGlobal } from '@/lib/store';
-import { jsonSchemaToZod } from '@/lib/utils';
+import { cn, jsonSchemaToZod } from '@/lib/utils';
import type { Resolver } from 'react-hook-form';
@@ -83,6 +83,7 @@ export const Go: React.FC = () => {
}
const baseForm = formSchema[provider.auth_mode];
+ const defaultValues: Record = {};
// To order fields we use incremented int starting high because we don't know yet which fields will be sorted
// It's a lazy algorithm that works most of the time
@@ -98,6 +99,9 @@ export const Go: React.FC = () => {
// Modify base form with credentials specific
for (const [name, schema] of Object.entries(provider.credentials || [])) {
baseForm.shape[name] = jsonSchemaToZod(schema);
+ if (schema.default_value) {
+ defaultValues[`credentials.${name}`] = schema.default_value;
+ }
}
// Append connectionConfig object
@@ -288,38 +292,42 @@ export const Go: React.FC = () => {
const base = name in defaultConfiguration ? defaultConfiguration[name] : undefined;
return (
-