Path: blob/main/components/dashboard/src/teams/onboarding/WelcomeMessageConfigurationField.tsx
2501 views
/**1* Copyright (c) 2025 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { SwitchInputField } from "@podkit/switch/Switch";7import { Heading3, Subheading } from "@podkit/typography/Headings";8import { useCallback, useState } from "react";9import { InputField } from "../../components/forms/InputField";10import { useToast } from "../../components/toasts/Toasts";11import { useIsOwner } from "../../data/organizations/members-query";12import { useOrgSettingsQuery } from "../../data/organizations/org-settings-query";13import {14UpdateOrganizationSettingsArgs,15useUpdateOrgSettingsMutation,16} from "../../data/organizations/update-org-settings-mutation";17import { ConfigurationSettingsField } from "../../repositories/detail/ConfigurationSettingsField";18import { UpdateTeamSettingsOptions } from "../TeamOnboarding";19import { WelcomeMessageEditorModal } from "./WelcomeMessageEditor";20import { WelcomeMessagePreview } from "./WelcomeMessagePreview";2122export const gitpodWelcomeSubheading =23`With Gitpod, you'll start coding instantly in a pre-configured environment that matches your team's setup, giving you the freedom to focus on what matters most: writing great code.` as const;2425type Props = {26handleUpdateTeamSettings: (27newSettings: UpdateOrganizationSettingsArgs,28options?: UpdateTeamSettingsOptions,29) => Promise<void>;30};31export const WelcomeMessageConfigurationField = ({ handleUpdateTeamSettings }: Props) => {32const { data: settings } = useOrgSettingsQuery();33const { toast } = useToast();34const isOwner = useIsOwner();35const updateTeamSettings = useUpdateOrgSettingsMutation();3637const [welcomeMessageEditorOpen, setWelcomeMessageEditorOpen] = useState(false);3839const handleUpdateWelcomeMessage = useCallback(40async (41newSettings: NonNullable<UpdateOrganizationSettingsArgs["onboardingSettings"]>["welcomeMessage"],42options?: UpdateTeamSettingsOptions,43) => {44await handleUpdateTeamSettings(45{46onboardingSettings: {47welcomeMessage: newSettings,48},49},50options,51);52},53[handleUpdateTeamSettings],54);5556return (57<ConfigurationSettingsField>58<Heading3>Welcome message</Heading3>59<Subheading>60A welcome message to your organization members. This message will be shown to your organization members61once they sign up and join your organization.62</Subheading>6364<InputField65label="Enabled"66hint={<>Enable showing the message to new organization members.</>}67id="show-welcome-message"68>69<SwitchInputField70id="show-welcome-message"71checked={settings?.onboardingSettings?.welcomeMessage?.enabled ?? false}72disabled={!isOwner || updateTeamSettings.isLoading}73onCheckedChange={(checked) => {74if (checked) {75if (!settings?.onboardingSettings?.welcomeMessage?.message) {76toast("Please set up a welcome message first.");77return;78}79}8081handleUpdateWelcomeMessage({ enabled: checked });82}}83label=""84/>85</InputField>8687<WelcomeMessageEditorModal88isLoading={updateTeamSettings.isLoading}89isOwner={isOwner}90isOpen={welcomeMessageEditorOpen}91setIsOpen={setWelcomeMessageEditorOpen}92handleUpdateWelcomeMessage={handleUpdateWelcomeMessage}93settings={settings?.onboardingSettings?.welcomeMessage}94/>9596<span className="text-pk-content-secondary text-sm">97Here's a preview of the welcome message that will be shown to your organization members:98</span>99<WelcomeMessagePreview100setWelcomeMessageEditorOpen={setWelcomeMessageEditorOpen}101disabled={!isOwner || updateTeamSettings.isLoading}102/>103</ConfigurationSettingsField>104);105};106107108