Skip to content

Commit

Permalink
changed to mutate
Browse files Browse the repository at this point in the history
  • Loading branch information
lowtorola committed May 13, 2024
1 parent 4a78925 commit 78bb0d1
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 41 deletions.
2 changes: 2 additions & 0 deletions frontend2/src/api/compete/useCompete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export const useRequestScrimmage = (
episodeId: string;
},
queryClient: QueryClient,
onSuccess?: () => void,
): UseMutationResult<
ScrimmageRequest,
Error,
Expand Down Expand Up @@ -378,6 +379,7 @@ export const useRequestScrimmage = (
error: "Error requesting scrimmage. Is the requested team eligible?",
});
},
onSuccess,
});

/**
Expand Down
2 changes: 2 additions & 0 deletions frontend2/src/api/team/useTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const useJoinTeam = (
export const useLeaveTeam = (
{ episodeId }: { episodeId: string },
queryClient: QueryClient,
onSuccess?: () => void,
): UseMutationResult<void, Error, void, unknown> =>
useMutation({
mutationKey: teamMutationKeys.leave({ episodeId }),
Expand All @@ -152,6 +153,7 @@ export const useLeaveTeam = (
});
},
onSuccess: async () => {
onSuccess?.();
await queryClient.invalidateQueries({
queryKey: buildKey(myTeamFactory.queryKey, { episodeId }),
});
Expand Down
29 changes: 12 additions & 17 deletions frontend2/src/components/tables/scrimmaging/RequestScrimModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const RequestScrimModal: React.FC<RequestScrimModalProps> = ({
}) => {
const { episodeId } = useEpisodeId();
const queryClient = useQueryClient();
const request = useRequestScrimmage({ episodeId }, queryClient);
const request = useRequestScrimmage({ episodeId }, queryClient, () => {
closeModal();
});

const getRandomMaps: () => string[] = useCallback(() => {
const possibleMaps = clone(maps);
Expand Down Expand Up @@ -141,22 +143,15 @@ const RequestScrimModal: React.FC<RequestScrimModalProps> = ({
disabled={mapErrorMessage !== undefined}
loading={request.isPending}
onClick={() => {
void request
.mutateAsync({
episodeId,
scrimmageRequestRequest: {
requested_to: teamToRequest.id,
is_ranked: ranked,
map_names: selectedMapNames,
player_order: selectedOrder,
},
})
.then(() => {
closeModal();
})
.catch((err: string) => {
console.error(`Error requesting scrimmage: ${err}`);
});
request.mutate({
episodeId,
scrimmageRequestRequest: {
requested_to: teamToRequest.id,
is_ranked: ranked,
map_names: selectedMapNames,
player_order: selectedOrder,
},
});
}}
/>
<Button fullWidth label="Cancel" onClick={closeModal} />
Expand Down
14 changes: 6 additions & 8 deletions frontend2/src/views/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ const Account: React.FC = () => {
const { register: resumeRegister, handleSubmit: handleResumeSubmit } =
useForm<FileInput>();

const onAvatarSubmit: SubmitHandler<FileInput> = async (data) => {
const onAvatarSubmit: SubmitHandler<FileInput> = (data) => {
if (uploadAvatar.isPending) return;
await uploadAvatar.mutateAsync({ avatar: data.file[0] });
uploadAvatar.mutate({ avatar: data.file[0] });
};

const onResumeSubmit: SubmitHandler<FileInput> = async (data) => {
const onResumeSubmit: SubmitHandler<FileInput> = (data) => {
if (uploadResume.isPending) return;
await uploadResume.mutateAsync({ resume: data.file[0] });
uploadResume.mutate({ resume: data.file[0] });
};

return (
Expand Down Expand Up @@ -167,10 +167,8 @@ const ProfileForm: React.FC<{
user?.profile?.country,
);

const onProfileSubmit: SubmitHandler<PatchedUserPrivateRequest> = async (
data,
) => {
await updateCurrentUser.mutateAsync({ patchedUserPrivateRequest: data });
const onProfileSubmit: SubmitHandler<PatchedUserPrivateRequest> = (data) => {
updateCurrentUser.mutate({ patchedUserPrivateRequest: data });
};

return (
Expand Down
8 changes: 4 additions & 4 deletions frontend2/src/views/JoinTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const JoinTeam: React.FC = () => {
<div className="flex flex-1 flex-col gap-8 xl:max-w-4xl">
<form
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onSubmit={handleCreateSubmit(async (data) => {
await createTeam.mutateAsync({ name: data.teamName });
onSubmit={handleCreateSubmit((data) => {
createTeam.mutate({ name: data.teamName });
resetCreate();
})}
>
Expand All @@ -69,8 +69,8 @@ const JoinTeam: React.FC = () => {
</form>
<form
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onSubmit={handleJoinSubmit(async (data) => {
await joinTeam.mutateAsync({
onSubmit={handleJoinSubmit((data) => {
joinTeam.mutate({
name: data.teamName,
join_key: data.joinKey,
});
Expand Down
17 changes: 9 additions & 8 deletions frontend2/src/views/MyTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const MyTeam: React.FC = () => {
reset,
} = useForm<InfoFormInput>();

const [isLeaveModalOpen, setIsLeaveModalOpen] = useState<boolean>(false);

const teamData = useUserTeam({ episodeId });
const updateTeam = useUpdateTeam(
{
Expand All @@ -43,10 +45,11 @@ const MyTeam: React.FC = () => {
episodeId,
},
queryClient,
() => {
setIsLeaveModalOpen(false);
},
);

const [isLeaveModalOpen, setIsLeaveModalOpen] = useState<boolean>(false);

const membersList = useMemo(() => {
return (
<div className="flex flex-col gap-8">
Expand All @@ -66,9 +69,9 @@ const MyTeam: React.FC = () => {
);
}, [teamData]);

const onSubmit: SubmitHandler<InfoFormInput> = async (data) => {
const onSubmit: SubmitHandler<InfoFormInput> = (data) => {
if (updateTeam.isPending) return;
await updateTeam.mutateAsync({
updateTeam.mutate({
profile: {
quote: data.quote,
biography: data.biography,
Expand All @@ -78,13 +81,12 @@ const MyTeam: React.FC = () => {
};

// eslint-disable-next-line @typescript-eslint/no-misused-promises
const onLeaveTeam: EventHandler<React.MouseEvent<HTMLButtonElement>> = async (
const onLeaveTeam: EventHandler<React.MouseEvent<HTMLButtonElement>> = (
event,
) => {
if (leaveTeam.isPending) return;
event.preventDefault();
await leaveTeam.mutateAsync();
setIsLeaveModalOpen(false);
leaveTeam.mutate();
};

if (teamData.isLoading) {
Expand All @@ -108,7 +110,6 @@ const MyTeam: React.FC = () => {
<img
className="h-24 w-24 rounded-full bg-gray-400 md:h-48 md:w-48"
src={teamData.data.profile?.avatar_url}
// TODO: open add avatar modal on click! With hover effect!
/>
<div className="text-center text-xl font-semibold">
{teamData.data.name}
Expand Down
4 changes: 2 additions & 2 deletions frontend2/src/views/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const Register: React.FC = () => {
}
}, [authState]);

const onSubmit: SubmitHandler<UserCreateRequest> = async (data) => {
const onSubmit: SubmitHandler<UserCreateRequest> = (data) => {
if (gender === undefined || country === undefined) {
return;
}
await createUser.mutateAsync({ userCreateRequest: data });
createUser.mutate({ userCreateRequest: data });
};

return (
Expand Down
4 changes: 2 additions & 2 deletions frontend2/src/views/Submissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const Submissions: React.FC = () => {
formState: { errors, isDirty },
} = useForm<SubmissionFormInput>();

const onSubmit: SubmitHandler<SubmissionFormInput> = async (data) => {
const onSubmit: SubmitHandler<SubmissionFormInput> = (data) => {
if (uploadSub.isPending) return;
await uploadSub.mutateAsync({
uploadSub.mutate({
episodeId,
_package: data.packageName,
description: data.description,
Expand Down

0 comments on commit 78bb0d1

Please sign in to comment.