|
| 1 | +/** |
| 2 | + * Copyright (c) 2025 Gitpod GmbH. All rights reserved. |
| 3 | + * Licensed under the GNU Affero General Public License (AGPL). |
| 4 | + * See License.AGPL.txt in the project root for license information. |
| 5 | + */ |
| 6 | + |
| 7 | +import { OrganizationSettings } from "@gitpod/public-api/lib/gitpod/v1/organization_pb"; |
| 8 | +import { FormEvent, useCallback, useEffect, useState } from "react"; |
| 9 | +import { Heading2, Heading3, Subheading } from "../components/typography/headings"; |
| 10 | +import { useIsOwner } from "../data/organizations/members-query"; |
| 11 | +import { useOrgSettingsQuery } from "../data/organizations/org-settings-query"; |
| 12 | +import { useCurrentOrg } from "../data/organizations/orgs-query"; |
| 13 | +import { useUpdateOrgSettingsMutation } from "../data/organizations/update-org-settings-mutation"; |
| 14 | +import { OrgSettingsPage } from "./OrgSettingsPage"; |
| 15 | +import { ConfigurationSettingsField } from "../repositories/detail/ConfigurationSettingsField"; |
| 16 | +import { useDocumentTitle } from "../hooks/use-document-title"; |
| 17 | +import { useToast } from "../components/toasts/Toasts"; |
| 18 | +import type { PlainMessage } from "@bufbuild/protobuf"; |
| 19 | +import { InputField } from "../components/forms/InputField"; |
| 20 | +import { TextInput } from "../components/forms/TextInputField"; |
| 21 | +import { LoadingButton } from "@podkit/buttons/LoadingButton"; |
| 22 | + |
| 23 | +export default function TeamOnboardingPage() { |
| 24 | + useDocumentTitle("Organization Settings - Onboarding"); |
| 25 | + const { toast } = useToast(); |
| 26 | + const org = useCurrentOrg().data; |
| 27 | + const isOwner = useIsOwner(); |
| 28 | + |
| 29 | + const { data: settings } = useOrgSettingsQuery(); |
| 30 | + const updateTeamSettings = useUpdateOrgSettingsMutation(); |
| 31 | + |
| 32 | + const [internalLink, setInternalLink] = useState<string | undefined>(undefined); |
| 33 | + |
| 34 | + const handleUpdateTeamSettings = useCallback( |
| 35 | + async (newSettings: Partial<PlainMessage<OrganizationSettings>>, options?: { throwMutateError?: boolean }) => { |
| 36 | + if (!org?.id) { |
| 37 | + throw new Error("no organization selected"); |
| 38 | + } |
| 39 | + if (!isOwner) { |
| 40 | + throw new Error("no organization settings change permission"); |
| 41 | + } |
| 42 | + try { |
| 43 | + await updateTeamSettings.mutateAsync({ |
| 44 | + ...settings, |
| 45 | + ...newSettings, |
| 46 | + }); |
| 47 | + toast("Organization settings updated"); |
| 48 | + } catch (error) { |
| 49 | + if (options?.throwMutateError) { |
| 50 | + throw error; |
| 51 | + } |
| 52 | + toast(`Failed to update organization settings: ${error.message}`); |
| 53 | + console.error(error); |
| 54 | + } |
| 55 | + }, |
| 56 | + [updateTeamSettings, org?.id, isOwner, settings, toast], |
| 57 | + ); |
| 58 | + |
| 59 | + const handleUpdateInternalLink = useCallback( |
| 60 | + async (e: FormEvent) => { |
| 61 | + e.preventDefault(); |
| 62 | + |
| 63 | + await handleUpdateTeamSettings({ onboardingSettings: { internalLink } }); |
| 64 | + }, |
| 65 | + [handleUpdateTeamSettings, internalLink], |
| 66 | + ); |
| 67 | + |
| 68 | + useEffect(() => { |
| 69 | + if (settings) { |
| 70 | + setInternalLink(settings.onboardingSettings?.internalLink); |
| 71 | + } |
| 72 | + }, [settings]); |
| 73 | + |
| 74 | + return ( |
| 75 | + <OrgSettingsPage> |
| 76 | + <div className="space-y-8"> |
| 77 | + <div> |
| 78 | + <Heading2>Policies</Heading2> |
| 79 | + <Subheading>Restrict workspace classes, editors and sharing across your organization.</Subheading> |
| 80 | + </div> |
| 81 | + <ConfigurationSettingsField> |
| 82 | + <Heading3>Internal dashboard</Heading3> |
| 83 | + <Subheading> |
| 84 | + The link to your internal dashboard. This link will be shown to your organization members during |
| 85 | + the onboarding process. You can disable showing a link by leaving this field empty. |
| 86 | + </Subheading> |
| 87 | + <form onSubmit={handleUpdateInternalLink}> |
| 88 | + <InputField label="Internal dashboard link" error={undefined} className="mb-4"> |
| 89 | + <TextInput |
| 90 | + value={internalLink} |
| 91 | + type="url" |
| 92 | + placeholder="https://en.wikipedia.org/wiki/Heisenbug" |
| 93 | + onChange={setInternalLink} |
| 94 | + disabled={updateTeamSettings.isLoading || !isOwner} |
| 95 | + /> |
| 96 | + </InputField> |
| 97 | + <LoadingButton type="submit" loading={updateTeamSettings.isLoading} disabled={!isOwner}> |
| 98 | + Save |
| 99 | + </LoadingButton> |
| 100 | + </form> |
| 101 | + </ConfigurationSettingsField> |
| 102 | + </div> |
| 103 | + </OrgSettingsPage> |
| 104 | + ); |
| 105 | +} |
0 commit comments