-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* UI feat: allow users to edit oauth apps Signed-off-by: Ryan Hopper-Lowe <[email protected]> * UI enhance: improve delete oauth app workflow * UI enhance: update oauth app delete button variant * UI chore: add error messages to oauth app api calls Signed-off-by: Ryan Hopper-Lowe <[email protected]> * UI refactor: prepopulate cache with oath data on page load * UI chore: reduce complexity + improve typesafety of OAuth app spec * Add header content for OAuth Apps * UI enhance: improve coloring on delete button confirmation * UI fix: prevent global swr revalidation on focus --------- Signed-off-by: Ryan Hopper-Lowe <[email protected]>
- Loading branch information
1 parent
d999952
commit 75b7fc4
Showing
12 changed files
with
333 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ComponentProps, ReactNode } from "react"; | ||
|
||
import { Button } from "~/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "~/components/ui/dialog"; | ||
|
||
export function ConfirmationDialog({ | ||
children, | ||
title, | ||
description, | ||
onConfirm, | ||
onCancel, | ||
confirmProps, | ||
...dialogProps | ||
}: ComponentProps<typeof Dialog> & { | ||
children?: ReactNode; | ||
title: ReactNode; | ||
description?: ReactNode; | ||
onConfirm: () => void; | ||
onCancel?: () => void; | ||
confirmProps?: Omit<Partial<ComponentProps<typeof Button>>, "onClick">; | ||
}) { | ||
return ( | ||
<Dialog {...dialogProps}> | ||
{children && <DialogTrigger asChild>{children}</DialogTrigger>} | ||
|
||
<DialogContent> | ||
<DialogTitle>{title}</DialogTitle> | ||
<DialogDescription>{description}</DialogDescription> | ||
<DialogFooter> | ||
<DialogClose onClick={onCancel} asChild> | ||
<Button variant="secondary">Cancel</Button> | ||
</DialogClose> | ||
|
||
<Button {...confirmProps} onClick={onConfirm}> | ||
{confirmProps?.children ?? "Confirm"} | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
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,68 @@ | ||
import { SquarePenIcon } from "lucide-react"; | ||
import { mutate } from "swr"; | ||
|
||
import { OAuthApp } from "~/lib/model/oauthApps"; | ||
import { OauthAppService } from "~/lib/service/api/oauthAppService"; | ||
|
||
import { Button } from "~/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "~/components/ui/dialog"; | ||
import { useOAuthAppSpec } from "~/hooks/oauthApps/useOAuthAppSpec"; | ||
import { useAsync } from "~/hooks/useAsync"; | ||
import { useDisclosure } from "~/hooks/useDisclosure"; | ||
|
||
import { OAuthAppForm } from "./OAuthAppForm"; | ||
|
||
type EditOAuthAppProps = { | ||
oauthApp: OAuthApp; | ||
}; | ||
|
||
export function EditOAuthApp({ oauthApp }: EditOAuthAppProps) { | ||
const updateApp = useAsync(OauthAppService.updateOauthApp, { | ||
onSuccess: async () => { | ||
await mutate(OauthAppService.getOauthApps.key()); | ||
modal.onClose(); | ||
}, | ||
}); | ||
|
||
const modal = useDisclosure(); | ||
|
||
const { data: spec } = useOAuthAppSpec(); | ||
|
||
const typeSpec = spec.get(oauthApp.type); | ||
if (!typeSpec) return null; | ||
|
||
return ( | ||
<Dialog open={modal.isOpen} onOpenChange={modal.onOpenChange}> | ||
<DialogTrigger asChild> | ||
<Button variant="ghost" size="icon"> | ||
<SquarePenIcon /> | ||
</Button> | ||
</DialogTrigger> | ||
|
||
<DialogContent> | ||
<DialogTitle>Edit OAuth App ({oauthApp.type})</DialogTitle> | ||
|
||
<DialogDescription hidden> | ||
Update the OAuth app settings. | ||
</DialogDescription> | ||
|
||
<OAuthAppForm | ||
appSpec={typeSpec} | ||
oauthApp={oauthApp} | ||
onSubmit={(data) => | ||
updateApp.execute(oauthApp.id, { | ||
type: oauthApp.type, | ||
...data, | ||
}) | ||
} | ||
/> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
Oops, something went wrong.