Skip to content

Commit

Permalink
Re-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Nov 13, 2023
1 parent 82a2f56 commit e5b5851
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@ export const useConfiguration = (configurationId: string) => {
});
};

export const useDeleteConfiguration = (configurationId: string) => {
type DeleteConfigurationArgs = {
configurationId: string;
};
export const useDeleteConfiguration = () => {
const queryClient = useQueryClient();

return useMutation<void, Error>({
mutationKey: getConfigurationQueryKey(configurationId),
mutationFn: async () => {
await configurationClient.deleteConfiguration({
return useMutation({
mutationFn: async ({ configurationId }: DeleteConfigurationArgs) => {
return await configurationClient.deleteConfiguration({
configurationId,
});
},
onSuccess: () => {
onSuccess: (_, { configurationId }) => {
queryClient.invalidateQueries({ queryKey: ["configurations", "list"] });
queryClient.invalidateQueries({ queryKey: getConfigurationQueryKey(configurationId) });
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import { FC } from "react";
import { useParams } from "react-router";
import { ConfigurationNameForm } from "./ConfigurationName";
import { ConfigurationNameForm } from "./general/ConfigurationName";
import { ConfigurationDetailPage } from "./ConfigurationDetailPage";
import { useConfiguration } from "../../data/configurations/configuration-queries";
import { RemoveConfiguration } from "./RemoveConfiguration";
import { RemoveConfiguration } from "./general/RemoveConfiguration";

type PageRouteParams = {
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configurati
import { Button } from "@podkit/buttons/Button";
import { LoadingButton } from "@podkit/buttons/LoadingButton";
import { FC, useCallback } from "react";
import { TextInputField } from "../../components/forms/TextInputField";
import { useToast } from "../../components/toasts/Toasts";
import { useUpdateProject } from "../../data/projects/project-queries";
import { useOnBlurError } from "../../hooks/use-onblur-error";
import { ConfigurationSettingsField } from "./ConfigurationSettingsField";
import { useDirtyState } from "../../hooks/use-dirty-state";
import { TextInputField } from "../../../components/forms/TextInputField";
import { useToast } from "../../../components/toasts/Toasts";
import { useUpdateProject } from "../../../data/projects/project-queries";
import { useOnBlurError } from "../../../hooks/use-onblur-error";
import { ConfigurationSettingsField } from "../ConfigurationSettingsField";
import { useDirtyState } from "../../../hooks/use-dirty-state";

const MAX_LENGTH = 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import { Heading2, Subheading } from "@podkit/typography/Headings";
import { Button } from "../../components/Button";
import { Button } from "../../../components/Button";
import { RemoveConfigurationModal } from "./RemoveConfigurationModal";
import { useHistory } from "react-router";
import { useCallback, useState } from "react";
import type { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
import { ConfigurationSettingsField } from "./ConfigurationSettingsField";
import { ConfigurationSettingsField } from "../ConfigurationSettingsField";

interface Props {
configuration: Configuration;
Expand All @@ -21,7 +21,7 @@ export const RemoveConfiguration = ({ configuration }: Props) => {

const history = useHistory();
const onProjectRemoved = useCallback(() => {
history.push("/projects");
history.push("/repositories");
}, [history]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

import { FunctionComponent, useCallback } from "react";
import ConfirmationModal from "../../components/ConfirmationModal";
import ConfirmationModal from "../../../components/ConfirmationModal";
import type { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
import { useDeleteConfiguration } from "../../data/configurations/configuration-queries";
import { useDeleteConfiguration } from "../../../data/configurations/configuration-queries";

type RemoveProjectModalProps = {
configuration: Configuration;
Expand All @@ -20,13 +20,16 @@ export const RemoveConfigurationModal: FunctionComponent<RemoveProjectModalProps
onClose,
onRemoved,
}) => {
const removeConfigMutation = useDeleteConfiguration(configuration.id);
const removeConfigMutation = useDeleteConfiguration();

const removeProject = useCallback(async () => {
removeConfigMutation.mutate(undefined, {
onSuccess: () => onRemoved(),
});
}, [removeConfigMutation, onRemoved]);
removeConfigMutation.mutate(
{ configurationId: configuration.id },
{
onSuccess: () => onRemoved(),
},
);
}, [removeConfigMutation, configuration.id, onRemoved]);

return (
<ConfirmationModal
Expand Down

0 comments on commit e5b5851

Please sign in to comment.