Skip to content

Commit

Permalink
upadte query cache after create
Browse files Browse the repository at this point in the history
  • Loading branch information
selfcontained committed Nov 15, 2023
1 parent cdf7c5f commit b645a43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type CreateConfigurationArgs = {

export const useCreateConfiguration = () => {
const { data: org } = useCurrentOrg();
const queryClient = useQueryClient();

return useMutation<Configuration, Error, CreateConfigurationArgs>({
mutationFn: async ({ name, cloneUrl }) => {
Expand All @@ -118,5 +119,9 @@ export const useCreateConfiguration = () => {

return response.configuration;
},
onSuccess: (configuration) => {
queryClient.setQueryData(getConfigurationQueryKey(configuration.id), configuration);
queryClient.invalidateQueries({ queryKey: ["configurations", "list"] });
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

import { FC, useCallback, useState } from "react";
import Modal, { ModalBody, ModalFooter, ModalFooterAlert, ModalHeader } from "../../components/Modal";
import { Button } from "../../components/Button";
import { SuggestedRepository } from "@gitpod/gitpod-protocol";
import RepositoryFinder from "../../components/RepositoryFinder";
import { InputField } from "../../components/forms/InputField";
import { AuthorizeGit, useNeedsGitAuthorization } from "../../components/AuthorizeGit";
import { useTemporaryState } from "../../hooks/use-temporary-value";
import { CreateConfigurationArgs, useCreateConfiguration } from "../../data/configurations/configuration-queries";
import type { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
import { LoadingButton } from "@podkit/buttons/LoadingButton";
import { Button } from "@podkit/buttons/Button";

type Props = {
onCreated: (configuration: Configuration) => void;
Expand Down Expand Up @@ -57,7 +58,7 @@ export const ImportRepositoryModal: FC<Props> = ({ onClose, onCreated }) => {
<AuthorizeGit />
) : (
<>
<InputField label="Select a repository" className="mb-8 w-full">
<InputField className="mb-8 w-full">
<RepositoryFinder
selectedContextURL={selectedRepo?.url}
selectedProjectID={selectedRepo?.projectId}
Expand All @@ -78,12 +79,12 @@ export const ImportRepositoryModal: FC<Props> = ({ onClose, onCreated }) => {
)
}
>
<Button type="secondary" onClick={onClose}>
<Button variant="secondary" onClick={onClose}>
Cancel
</Button>
<Button htmlType="submit" loading={createConfiguration.isLoading}>
<LoadingButton type="submit" loading={createConfiguration.isLoading}>
Import
</Button>
</LoadingButton>
</ModalFooter>
</Modal>
);
Expand Down

0 comments on commit b645a43

Please sign in to comment.