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.

update the server action

Kiran K4019938bd6ec
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
index 776a71dc99..bbb61de666 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
@@ -27,7 +27,17 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
const searchParams = useSearchParams();
const { slug, id: workspaceId } = useWorkspace();
const [openPopover, setOpenPopover] = useState(false);
- const { executeAsync, result, status } = useAction(generateClientSecret);
+ const { executeAsync, result, isExecuting } = useAction(
+ generateClientSecret,
+ {
+ onSuccess: () => {
+ toast.success("New client secret generated.");
+ },
+ onError: ({ error }) => {
+ toast.error(error.serverError?.serverError);
+ },
+ },
+ );
const { data: oAuthApp, isLoading } = useSWR<OAuthAppProps>(
`/api/oauth/apps/${appId}?workspaceId=${workspaceId}`,
@@ -94,27 +104,17 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
content={
<div className="grid w-screen gap-px p-2 sm:w-48">
<Button
- text={
- status === "executing"
- ? "Regenerating..."
- : "Regenerate secret"
- }
+ text={isExecuting ? "Regenerating..." : "Regenerate secret"}
variant="outline"
icon={<RefreshCcw className="h-4 w-4" />}
className="h-9 justify-start px-2 font-medium"
- disabled={status === "executing"}
+ disabled={isExecuting}
onClick={async () => {
await executeAsync({
workspaceId: workspaceId!,
- integrationId: appId,
+ appId,
});
- if (status === "hasSucceeded") {
- toast.success("New client secret generated.");
- } else if (status === "hasErrored") {
- toast.error(result.serverError?.serverError);
- }
-
setOpenPopover(false);
}}
/>
diff --git a/apps/web/lib/actions/generate-client-secret.ts b/apps/web/lib/actions/generate-client-secret.ts
index cf3b3bd4ed..09ecae7831 100644
--- a/apps/web/lib/actions/generate-client-secret.ts
+++ b/apps/web/lib/actions/generate-client-secret.ts
@@ -9,7 +9,7 @@ import { authActionClient } from "./safe-action";
const schema = z.object({
workspaceId: z.string(),
- integrationId: z.string(),
+ appId: z.string(),
});
// Generate a new client secret for an integration
@@ -17,11 +17,11 @@ export const generateClientSecret = authActionClient
.schema(schema)
.action(async ({ ctx, parsedInput }) => {
const { workspace } = ctx;
- const { integrationId } = parsedInput;
+ const { appId } = parsedInput;
await prisma.oAuthApp.findFirstOrThrow({
where: {
- id: integrationId,
+ id: appId,
projectId: workspace.id,
},
});
@@ -33,7 +33,7 @@ export const generateClientSecret = authActionClient
await prisma.oAuthApp.update({
where: {
- id: integrationId,
+ id: appId,
},
data: {
hashedClientSecret: await hashToken(clientSecret),