| 1 | "use client"; |
| 2 | |
| 3 | import { useRouter } from |
| 4 | import { useAction } |
| 5 | import { useState } |
| 6 | import { toast } |
| 7 | |
| 8 | import { updateOauthApp } |
| 9 | import { |
| 10 | OauthAppFields, |
| 11 | type OauthAppValues, |
| 12 | oauthAppReady, |
| 13 | } from "@/components/oauth-apps/oauth-app-fields"; |
| 14 | import { SettingCard } |
| 15 | import type { components |
| 16 | |
| 17 | export function OauthAppSettingsCard({ |
| 18 | app, |
| 19 | }: { |
| 20 | app: components |
| 21 | }) { |
| 22 | const router = |
| 23 | const saved: |
| 24 | name: app.name |
| 25 | description: app.description |
| 26 | homepageUrl: app.homepageUrl |
| 27 | callbackUrls: app.callbackUrls |
| 28 | deviceFlowEnabled: app.deviceFlowEnabled |
| 29 | expireUserTokens: app.expireUserTokens |
| 30 | }; |
| 31 | const [values, |
| 32 | const update = |
| 33 | onSuccess: () => |
| 34 | toast.success("OAuth app saved |
| 35 | router.refresh(); |
| 36 | }, |
| 37 | onError: ({ error |
| 38 | toast.error(error |
| 39 | }); |
| 40 | const changed = |
| 41 | |
| 42 | return ( |
| 43 | <SettingCard |
| 44 | title="Settings" |
| 45 | hint="Changes apply to the next person who signs in." |
| 46 | onSubmit={() => |
| 47 | update.execute({ |
| 48 | clientId: app.clientId |
| 49 | ...values, |
| 50 | callbackUrls: values.callbackUrls |
| 51 | }) |
| 52 | } |
| 53 | pending={update.isExecuting |
| 54 | canSave={changed && |
| 55 | > |
| 56 | <OauthAppFields |
| 57 | values={values} |
| 58 | disabled={update.isExecuting |
| 59 | onChange={setValues} |
| 60 | /> |
| 61 | </SettingCard> |
| 62 | ); |
| 63 | } |