-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: disconnect alby account in auth code form (#833)
* feat: disconnect from Alby Account in OAuth form * fix: always show confirmation dialog when disconnecting alby account
- Loading branch information
Showing
4 changed files
with
120 additions
and
129 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
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,78 @@ | ||
import React from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { | ||
AlertDialog, | ||
AlertDialogAction, | ||
AlertDialogCancel, | ||
AlertDialogContent, | ||
AlertDialogDescription, | ||
AlertDialogFooter, | ||
AlertDialogHeader, | ||
AlertDialogTitle, | ||
AlertDialogTrigger, | ||
} from "src/components/ui/alert-dialog"; | ||
import { useToast } from "src/components/ui/use-toast"; | ||
import { useInfo } from "src/hooks/useInfo"; | ||
import { request } from "src/utils/request"; | ||
|
||
type UnlinkAlbyAccountProps = { | ||
navigateTo?: string; | ||
successMessage?: string; | ||
}; | ||
|
||
export function UnlinkAlbyAccount({ | ||
children, | ||
navigateTo = "/", | ||
successMessage = "Your hub is no longer connected to an Alby Account.", | ||
}: React.PropsWithChildren<UnlinkAlbyAccountProps>) { | ||
const { toast } = useToast(); | ||
const navigate = useNavigate(); | ||
const { mutate: refetchInfo } = useInfo(); | ||
|
||
const unlinkAccount = React.useCallback(async () => { | ||
try { | ||
await request("/api/alby/unlink-account", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
await refetchInfo(); | ||
navigate(navigateTo); | ||
toast({ | ||
title: "Alby Account Disconnected", | ||
description: successMessage, | ||
}); | ||
} catch (error) { | ||
toast({ | ||
title: "Disconnect account failed", | ||
description: (error as Error).message, | ||
variant: "destructive", | ||
}); | ||
} | ||
}, [refetchInfo, navigate, navigateTo, toast, successMessage]); | ||
|
||
return ( | ||
<AlertDialog> | ||
<AlertDialogTrigger asChild>{children}</AlertDialogTrigger> | ||
<AlertDialogContent> | ||
<AlertDialogHeader> | ||
<AlertDialogTitle>Disconnect Alby Account</AlertDialogTitle> | ||
<AlertDialogDescription> | ||
<div> | ||
<p>Are you sure you want to disconnect your Alby Account?</p> | ||
<p className="text-destructive font-medium mt-4"> | ||
Your Alby Account will be disconnected and all Alby Account | ||
features such as your lightning address will stop working. | ||
</p> | ||
</div> | ||
</AlertDialogDescription> | ||
</AlertDialogHeader> | ||
<AlertDialogFooter> | ||
<AlertDialogCancel>Cancel</AlertDialogCancel> | ||
<AlertDialogAction onClick={unlinkAccount}>Confirm</AlertDialogAction> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
); | ||
} |
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