Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/repositories/detail/variables/ConfigurationRemoveVariableModal.tsx
2502 views
1
/**
2
* Copyright (c) 2023 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 { FunctionComponent, useCallback } from "react";
8
import { useToast } from "../../../components/toasts/Toasts";
9
import ConfirmationModal from "../../../components/ConfirmationModal";
10
import { useDeleteConfigurationVariable } from "../../../data/configurations/configuration-queries";
11
import type { ConfigurationEnvironmentVariable } from "@gitpod/public-api/lib/gitpod/v1/envvar_pb";
12
13
type Props = {
14
variable: ConfigurationEnvironmentVariable;
15
configurationId: string;
16
onClose(): void;
17
};
18
export const ConfigurationDeleteVariableModal: FunctionComponent<Props> = ({ variable, configurationId, onClose }) => {
19
const deleteVariable = useDeleteConfigurationVariable();
20
const { toast } = useToast();
21
22
const handleConfirmation = useCallback(() => {
23
deleteVariable.mutate(
24
{ variableId: variable.id, configurationId },
25
{
26
onSuccess: () => {
27
toast("Your variable was deleted");
28
onClose();
29
},
30
onError: (err) => {
31
toast(`Could not delete variable: ${err.message}`);
32
},
33
},
34
);
35
}, [configurationId, deleteVariable, onClose, toast, variable.id]);
36
37
return (
38
<ConfirmationModal
39
title="Delete variable"
40
areYouSureText="Are you sure you want to delete this variable?"
41
children={{
42
name: variable.name,
43
}}
44
buttonText="Delete variable"
45
warningText={deleteVariable.isError ? "There was a problem deleting this variable." : undefined}
46
onClose={onClose}
47
onConfirm={handleConfirmation}
48
visible
49
/>
50
);
51
};
52
53