-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
518 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
apps/dashboard/src/actions/institutions/create-pluggy-link.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use server"; | ||
|
||
import { client } from "@midday/engine/client"; | ||
import { getSession } from "@midday/supabase/cached-queries"; | ||
|
||
export const createPluggyLinkTokenAction = async (accessToken?: string) => { | ||
const { | ||
data: { session }, | ||
} = await getSession(); | ||
|
||
if (!session?.user.id) { | ||
throw new Error("User not found"); | ||
} | ||
|
||
const pluggyResponse = await client.auth.pluggy.link.$post({ | ||
json: { | ||
userId: session.user.id, | ||
environment: "production", | ||
}, | ||
}); | ||
|
||
if (!pluggyResponse.ok) { | ||
throw new Error("Failed to create pluggy link token"); | ||
} | ||
|
||
const { data } = await pluggyResponse.json(); | ||
|
||
console.log(data); | ||
|
||
return data.access_token; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { useConnectParams } from "@/hooks/use-connect-params"; | ||
import { track } from "@midday/events/client"; | ||
import { LogEvents } from "@midday/events/events"; | ||
import { useTheme } from "next-themes"; | ||
import { useState } from "react"; | ||
import { PluggyConnect as PluggySDK } from "react-pluggy-connect"; | ||
import { BankConnectButton } from "./bank-connect-button"; | ||
|
||
type Props = { | ||
id: string; | ||
onSelect: (id: string) => void; | ||
}; | ||
|
||
export function PluggyConnect({ id, onSelect }: Props) { | ||
const [institution, setInstitution] = useState<string | undefined>(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const { setParams } = useConnectParams(); | ||
const { theme } = useTheme(); | ||
|
||
return ( | ||
<> | ||
<BankConnectButton | ||
onClick={() => { | ||
onSelect(id); | ||
setInstitution(id); | ||
setIsOpen(true); | ||
}} | ||
/> | ||
|
||
{isOpen && ( | ||
<PluggySDK | ||
theme={theme as "light" | "dark"} | ||
selectedConnectorId={Number(institution)} | ||
connectToken={"your-connect-token-here"} | ||
onError={() => { | ||
setParams({ step: "connect" }); | ||
track({ | ||
event: LogEvents.ConnectBankCanceled.name, | ||
channel: LogEvents.ConnectBankCanceled.channel, | ||
provider: "pluggy", | ||
}); | ||
|
||
setParams({ step: "connect" }); | ||
}} | ||
onSuccess={() => { | ||
// setParams({ | ||
// step: "account", | ||
// provider: "pluggy", | ||
// token: authorization.accessToken, | ||
// enrollment_id: authorization.enrollment.id, | ||
// }); | ||
// track({ | ||
// event: LogEvents.ConnectBankAuthorized.name, | ||
// channel: LogEvents.ConnectBankAuthorized.channel, | ||
// provider: "pluggy", | ||
// }); | ||
}} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as PluggyConnect from "pluggy-connect-sdk"; | ||
import { useEffect, useState } from "react"; | ||
|
||
type Props = { | ||
token: string; | ||
institutionId?: string; | ||
onExit: () => void; | ||
onSuccess: (itemData: any) => void; | ||
onError: () => void; | ||
includeSandbox?: boolean; | ||
}; | ||
|
||
export function usePluggyLink({ | ||
token, | ||
institutionId, | ||
onExit, | ||
onSuccess, | ||
onError, | ||
includeSandbox = false, | ||
}: Props) { | ||
const [connectToken, setConnectToken] = useState<string>(""); | ||
const [selectedConnectorId, setSelectedConnectorId] = useState< | ||
number | undefined | ||
>(institutionId ? Number(institutionId) : undefined); | ||
|
||
useEffect(() => { | ||
setConnectToken(token); | ||
}, [token]); | ||
|
||
const pluggyConnect = new PluggyConnect.PluggyConnect({ | ||
connectToken, | ||
includeSandbox, | ||
selectedConnectorId, | ||
onClose: onExit, | ||
onSuccess, | ||
onError, | ||
}); | ||
|
||
const handleOpen = ({ institutionId }: { institutionId?: string }) => { | ||
setSelectedConnectorId(Number(institutionId)); | ||
pluggyConnect.init(); | ||
}; | ||
|
||
return { | ||
open: handleOpen, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.