Skip to content

Commit c07582d

Browse files
Refactor and cleanup
1 parent 264b10a commit c07582d

File tree

16 files changed

+84
-33
lines changed

16 files changed

+84
-33
lines changed

components/discord/sources/message-deleted/message-deleted.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "discord-message-deleted",
55
name: "Message Deleted (Instant)",
66
description: "Emit new event for each message deleted",
7-
version: "0.0.3",
7+
version: "0.0.4",
88
dedupe: "unique",
99
type: "source",
1010
props: {

components/discord/sources/new-command-received/new-command-received.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "discord-new-command-received",
77
name: "New Command Received (Instant)",
88
description: "Emit new event for each command posted to one or more channels in a Discord server",
9-
version: "0.0.3",
9+
version: "0.0.4",
1010
dedupe: "unique",
1111
props: {
1212
discord,

components/discord/sources/new-guild-member/new-guild-member.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "discord-new-guild-member",
55
name: "New Guild Member (Instant)",
66
description: "Emit new event for each new member added to a guild",
7-
version: "0.0.3",
7+
version: "0.0.4",
88
dedupe: "unique",
99
type: "source",
1010
props: {

components/discord/sources/new-message/new-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "discord-new-message",
77
name: "New Message (Instant)",
88
description: "Emit new event for each message posted to one or more channels in a Discord server",
9-
version: "1.0.3",
9+
version: "1.0.4",
1010

1111
dedupe: "unique",
1212
props: {

components/discord/sources/reaction-added/reaction-added.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "discord-reaction-added",
55
name: "Reaction Added (Instant)",
66
description: "Emit new event for each reaction added to a message",
7-
version: "0.0.3",
7+
version: "0.0.4",
88
type: "source",
99
props: {
1010
discord,

packages/connect-react/README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default function Page() {
9797
<div>My application</div>
9898
<FrontendClientProvider client={client}>
9999
<ComponentFormContainer
100-
userId={userId}
100+
externalUserId={userId}
101101
componentKey="slack-send-message"
102102
configuredProps={configuredProps}
103103
onUpdateConfiguredProps={setConfiguredProps}
@@ -137,25 +137,51 @@ type ComponentFormContainerProps = {
137137
type ComponentFormProps = {
138138
component: typeof import("@pipedream/sdk").V1Component;
139139
/** External user configuring the form */
140-
userId: string;
140+
externalUserId: string;
141+
/** @deprecated Use externalUserId instead */
142+
userId?: string;
141143
/** Form configured values */
142144
configuredProps?: Record<string, any>;
143145
/** Filtering configurable props */
144146
propNames?: string[];
145147
/** Shows submit button + callback when clicked */
146-
onSubmit: (ctx: FormContext) => Awaitable<void>;
148+
onSubmit?: (ctx: FormContext) => Awaitable<void>;
147149
/** To control and store configured values on form updates, can be used to call actionRun or triggerDeploy */
148-
onUpdateConfiguredProps: (v: Record<string, any>) => void;
150+
onUpdateConfiguredProps?: (v: Record<string, any>) => void;
149151
/** Hide optional props section */
150-
hideOptionalProps: boolean;
152+
hideOptionalProps?: boolean;
151153
/** SDK response payload. Used in conjunction with enableDebugging to
152154
* show errors in the form. */
153-
sdkResponse: unknown[] | unknown | undefined;
154-
/** Whether to show show errors in the form. Requires sdkErrors to be set. */
155+
sdkResponse?: unknown[] | unknown | undefined;
156+
/** Whether to show errors in the form. Requires sdkResponse to be set. */
155157
enableDebugging?: boolean;
158+
/** Optional OAuth app ID for app-specific account connections */
159+
oauthAppId?: string;
156160
};
157161
```
158162
163+
## OAuth Configuration
164+
165+
By default, apps use Pipedream OAuth clients. To configured your own, refer to the docs [here](https://pipedream.com/docs/connect/managed-auth/oauth-clients).
166+
167+
### Using a custom OAuth client
168+
169+
1. Create an OAuth app in your target service (e.g., Slack, Google, etc.)
170+
2. Configure the client in Pipedream ([refer to the docs](https://pipedream.com/docs/connect/managed-auth/oauth-clients))
171+
3. Use the `oauthAppId` prop to specify which OAuth client to use for account connections
172+
173+
```typescript
174+
<ComponentFormContainer
175+
externalUserId={userId}
176+
componentKey="slack-send-message-to-channel"
177+
configuredProps={configuredProps}
178+
onUpdateConfiguredProps={setConfiguredProps}
179+
oauthAppId="your-custom-oauth-app-id" // oa_xxxxxxx
180+
/>
181+
```
182+
183+
When `oauthAppId` is provided, all app connections within that component form will use your specified OAuth app instead of Pipedream's default.
184+
159185
## Customization
160186
161187
Style individual components using the `CustomizeProvider` and a `CustomizationConfig`.
@@ -164,7 +190,8 @@ Style individual components using the `CustomizeProvider` and a `CustomizationCo
164190
<FrontendClientProvider client={client}>
165191
<CustomizeProvider {...customizationConfig}>
166192
<ComponentFormContainer
167-
key="slack-send-message"
193+
externalUserId={userId}
194+
componentKey="slack-send-message"
168195
configuredProps={configuredProps}
169196
onUpdateConfiguredProps={setConfiguredProps}
170197
/>

packages/connect-react/src/components/ComponentForm.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
V1Component,
99
} from "@pipedream/sdk";
1010
import { InternalComponentForm } from "./InternalComponentForm";
11+
import { OAuthAppProvider } from "../hooks/oauth-app-context";
1112

1213
export type ComponentFormProps<T extends ConfigurableProps, U = ConfiguredProps<T>> = {
1314
/**
@@ -30,18 +31,19 @@ export type ComponentFormProps<T extends ConfigurableProps, U = ConfiguredProps<
3031
sdkResponse?: unknown | undefined;
3132
enableDebugging?: boolean;
3233
/**
33-
* The OAuth app ID to use when connecting accounts for app props.
34+
* Optional OAuth app ID for app-specific account connections
3435
*/
3536
oauthAppId?: string;
36-
} & (
37-
| { externalUserId: string; userId?: never }
38-
| { userId: string; externalUserId?: never }
39-
);
37+
};
4038

4139
export function ComponentForm<T extends ConfigurableProps>(props: ComponentFormProps<T>) {
40+
const { oauthAppId, ...formProps } = props;
41+
4242
return (
43-
<FormContextProvider props={props}>
44-
<InternalComponentForm />
45-
</FormContextProvider>
43+
<OAuthAppProvider oauthAppId={oauthAppId}>
44+
<FormContextProvider props={formProps}>
45+
<InternalComponentForm />
46+
</FormContextProvider>
47+
</OAuthAppProvider>
4648
);
4749
}

packages/connect-react/src/components/ComponentFormContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ export function ComponentFormContainer<T extends ConfigurableProps>(props: Compo
3737
}
3838

3939
// TODO move / improve lib.ts and make sure V1Component and it match / are shared
40-
return <ComponentForm component={component} {...props} />;
40+
const { componentKey, ...componentFormProps } = props;
41+
return <ComponentForm component={component} {...componentFormProps} />;
4142
}

packages/connect-react/src/components/Control.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function Control<T extends ConfigurableProps, U extends ConfigurableProp>
7474
// case "any":
7575
// return <ControlAny />
7676
case "app":
77-
return <ControlApp app={app!} oauthAppId={field.extra.oauthAppId} />;
77+
return <ControlApp app={app!} />;
7878
case "boolean":
7979
return <ControlBoolean />;
8080
case "string":

packages/connect-react/src/components/ControlApp.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useAccounts } from "../hooks/use-accounts";
44
import { useFormFieldContext } from "../hooks/form-field-context";
55
import { useFormContext } from "../hooks/form-context";
66
import { useCustomize } from "../hooks/customization-context";
7+
import { useOAuthAppContext } from "../hooks/oauth-app-context";
78
import type { BaseReactSelectProps } from "../hooks/customization-context";
89
import { useMemo } from "react";
910
import type { CSSProperties } from "react";
@@ -25,12 +26,12 @@ const BaseOption = (props: OptionProps<AppResponse>) => {
2526

2627
type ControlAppProps = {
2728
app: AppResponse;
28-
oauthAppId?: string;
2929
};
3030

31-
export function ControlApp({ app, oauthAppId }: ControlAppProps) {
31+
export function ControlApp({ app }: ControlAppProps) {
3232
const client = useFrontendClient();
3333
const { externalUserId } = useFormContext();
34+
const { oauthAppId } = useOAuthAppContext();
3435
const formFieldCtx = useFormFieldContext<ConfigurablePropApp>();
3536
const {
3637
id, prop, value, onChange,

0 commit comments

Comments
 (0)