-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI feat: Update UX for OAuth app configuration (#253)
* UI feat: Update UX for OAuth app configuration - add confirmation dialogs for updating OAuth apps Signed-off-by: Ryan Hopper-Lowe <[email protected]> * fix: update messages and links for GitHub OAuth workflow --------- Signed-off-by: Ryan Hopper-Lowe <[email protected]>
- Loading branch information
1 parent
c7b5650
commit fed5332
Showing
12 changed files
with
249 additions
and
276 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
ui/admin/app/components/oauth-apps/ConfigureOAuthApp.tsx
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,135 @@ | ||
import { SettingsIcon } from "lucide-react"; | ||
import { toast } from "sonner"; | ||
import { mutate } from "swr"; | ||
|
||
import { OAuthAppParams } from "~/lib/model/oauthApps"; | ||
import { OAuthProvider } from "~/lib/model/oauthApps/oauth-helpers"; | ||
import { OauthAppService } from "~/lib/service/api/oauthAppService"; | ||
|
||
import { Button } from "~/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "~/components/ui/dialog"; | ||
import { ScrollArea } from "~/components/ui/scroll-area"; | ||
import { | ||
useOAuthAppInfo, | ||
useOAuthAppList, | ||
} from "~/hooks/oauthApps/useOAuthApps"; | ||
import { useAsync } from "~/hooks/useAsync"; | ||
import { useDisclosure } from "~/hooks/useDisclosure"; | ||
|
||
import { OAuthAppForm } from "./OAuthAppForm"; | ||
import { OAuthAppTypeIcon } from "./OAuthAppTypeIcon"; | ||
|
||
export function ConfigureOAuthApp({ type }: { type: OAuthProvider }) { | ||
const spec = useOAuthAppInfo(type); | ||
const { customApp } = spec; | ||
const isEdit = !!customApp; | ||
|
||
const modal = useDisclosure(); | ||
const successModal = useDisclosure(); | ||
|
||
const createApp = useAsync(async (data: OAuthAppParams) => { | ||
await OauthAppService.createOauthApp({ | ||
type, | ||
refName: type, | ||
...data, | ||
}); | ||
|
||
await mutate(useOAuthAppList.key()); | ||
|
||
modal.onClose(); | ||
successModal.onOpen(); | ||
toast.success(`${spec.displayName} OAuth configuration created`); | ||
}); | ||
|
||
const updateApp = useAsync(async (data: OAuthAppParams) => { | ||
if (!customApp) throw new Error("Custom app not found"); | ||
|
||
await OauthAppService.updateOauthApp(customApp.id, { | ||
type: customApp.type, | ||
refName: customApp.refName, | ||
...data, | ||
}); | ||
|
||
await mutate(useOAuthAppList.key()); | ||
|
||
modal.onClose(); | ||
successModal.onOpen(); | ||
toast.success(`${spec.displayName} OAuth configuration updated`); | ||
}); | ||
|
||
return ( | ||
<> | ||
<Dialog open={modal.isOpen} onOpenChange={modal.onOpenChange}> | ||
<DialogTrigger asChild> | ||
<Button className="w-full"> | ||
<SettingsIcon className="w-4 h-4 mr-2" /> | ||
{isEdit | ||
? "Replace Configuration" | ||
: `Configure ${spec.displayName} OAuth App`} | ||
</Button> | ||
</DialogTrigger> | ||
|
||
<DialogContent | ||
classNames={{ | ||
overlay: "opacity-0", | ||
}} | ||
aria-describedby="create-oauth-app" | ||
className="px-0" | ||
> | ||
<DialogTitle className="flex items-center gap-2 px-4"> | ||
<OAuthAppTypeIcon type={type} /> | ||
Configure {spec.displayName} OAuth App | ||
</DialogTitle> | ||
|
||
<DialogDescription hidden> | ||
Create a new OAuth app for {spec.displayName} | ||
</DialogDescription> | ||
|
||
<ScrollArea className="max-h-[80vh] px-4"> | ||
<OAuthAppForm | ||
type={type} | ||
onSubmit={ | ||
isEdit ? updateApp.execute : createApp.execute | ||
} | ||
isLoading={ | ||
isEdit | ||
? updateApp.isLoading | ||
: createApp.isLoading | ||
} | ||
/> | ||
</ScrollArea> | ||
</DialogContent> | ||
</Dialog> | ||
|
||
<Dialog | ||
open={successModal.isOpen} | ||
onOpenChange={successModal.onOpenChange} | ||
> | ||
<DialogContent> | ||
<DialogTitle> | ||
Successfully Configured {spec.displayName} OAuth App | ||
</DialogTitle> | ||
|
||
<DialogDescription> | ||
Otto will now use your custom {spec.displayName} OAuth | ||
app to authenticate users. | ||
</DialogDescription> | ||
|
||
<DialogFooter> | ||
<DialogClose asChild> | ||
<Button className="w-full">Close</Button> | ||
</DialogClose> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
</> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.