|
| 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 { SwitchInputField } from "@podkit/switch/Switch"; |
| 8 | +import { Heading3, Subheading } from "@podkit/typography/Headings"; |
| 9 | +import { FC, useCallback } from "react"; |
| 10 | +import { InputField } from "../../../components/forms/InputField"; |
| 11 | +import PillLabel from "../../../components/PillLabel"; |
| 12 | +import { useToast } from "../../../components/toasts/Toasts"; |
| 13 | +import { useOrgSettingsQuery } from "../../../data/organizations/org-settings-query"; |
| 14 | +import { useUpdateOrgSettingsMutation } from "../../../data/organizations/update-org-settings-mutation"; |
| 15 | +import { useId } from "../../../hooks/useId"; |
| 16 | +import { ConfigurationSettingsField } from "../ConfigurationSettingsField"; |
| 17 | +import { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb"; |
| 18 | +import { SquareArrowOutUpRight } from "lucide-react"; |
| 19 | + |
| 20 | +type Props = { |
| 21 | + configuration: Configuration; |
| 22 | +}; |
| 23 | +export const ManageRepoSuggestion: FC<Props> = ({ configuration }) => { |
| 24 | + const { data: orgSettings } = useOrgSettingsQuery(); |
| 25 | + const { toast } = useToast(); |
| 26 | + const updateTeamSettings = useUpdateOrgSettingsMutation(); |
| 27 | + const updateRecommendedRepository = useCallback( |
| 28 | + async (configurationId: string, suggested: boolean) => { |
| 29 | + const newRepositories = new Set(orgSettings?.onboardingSettings?.recommendedRepositories ?? []); |
| 30 | + if (suggested) { |
| 31 | + newRepositories.add(configurationId); |
| 32 | + } else { |
| 33 | + newRepositories.delete(configurationId); |
| 34 | + } |
| 35 | + |
| 36 | + await updateTeamSettings.mutateAsync( |
| 37 | + { |
| 38 | + onboardingSettings: { |
| 39 | + ...orgSettings?.onboardingSettings, |
| 40 | + recommendedRepositories: [...newRepositories], |
| 41 | + }, |
| 42 | + }, |
| 43 | + { |
| 44 | + onError: (error) => { |
| 45 | + toast(`Failed to update recommended repositories: ${error.message}`); |
| 46 | + }, |
| 47 | + }, |
| 48 | + ); |
| 49 | + }, |
| 50 | + [orgSettings?.onboardingSettings, toast, updateTeamSettings], |
| 51 | + ); |
| 52 | + |
| 53 | + const isSuggested = orgSettings?.onboardingSettings?.recommendedRepositories?.includes(configuration.id); |
| 54 | + |
| 55 | + const inputId = useId({ prefix: "suggested-repository" }); |
| 56 | + |
| 57 | + return ( |
| 58 | + <ConfigurationSettingsField> |
| 59 | + <Heading3 className="flex flex-row items-center gap-2"> |
| 60 | + Mark this repository as{" "} |
| 61 | + <PillLabel className="capitalize bg-kumquat-light shrink-0 text-sm hidden xl:block" type="warn"> |
| 62 | + Suggested |
| 63 | + </PillLabel> |
| 64 | + </Heading3> |
| 65 | + <Subheading className="max-w-lg flex flex-col gap-2"> |
| 66 | + The Suggested section highlights recommended repositories on the dashboard for new members, making it |
| 67 | + easier to find and start working on key projects in Gitpod. |
| 68 | + <a |
| 69 | + className="gp-link flex flex-row items-center gap-1" |
| 70 | + href="https://www.gitpod.io/docs/configure/orgs/onboarding#suggested-repositories" |
| 71 | + target="_blank" |
| 72 | + rel="noreferrer" |
| 73 | + > |
| 74 | + Learn about suggestions |
| 75 | + <SquareArrowOutUpRight size={12} /> |
| 76 | + </a> |
| 77 | + </Subheading> |
| 78 | + <InputField id={inputId}> |
| 79 | + <SwitchInputField |
| 80 | + id={inputId} |
| 81 | + checked={isSuggested} |
| 82 | + disabled={updateTeamSettings.isLoading} |
| 83 | + onCheckedChange={(checked) => { |
| 84 | + updateRecommendedRepository(configuration.id, checked); |
| 85 | + }} |
| 86 | + label={isSuggested ? "Listed in “Suggested”" : "Not listed in “Suggested”"} |
| 87 | + /> |
| 88 | + </InputField> |
| 89 | + </ConfigurationSettingsField> |
| 90 | + ); |
| 91 | +}; |
0 commit comments