fix space translations (#826)

This commit is contained in:
Philip Okugbe
2025-03-07 00:03:57 +00:00
committed by GitHub
parent 1988feb9ce
commit 8826cca539
4 changed files with 35 additions and 15 deletions

View File

@ -25,6 +25,7 @@ import {
} from "@/features/space/services/space-service.ts";
import { notifications } from "@mantine/notifications";
import { IPagination, QueryParams } from "@/lib/types.ts";
import { useTranslation } from "react-i18next";
import { queryClient } from "@/main.tsx";
import { getRecentChanges } from "@/features/page/services/page-service.ts";
import { useEffect } from "react";
@ -76,6 +77,7 @@ export const prefetchSpace = (spaceSlug: string, spaceId?: string) => {
export function useCreateSpaceMutation() {
const queryClient = useQueryClient();
const { t } = useTranslation();
return useMutation<ISpace, Error, Partial<ISpace>>({
mutationFn: (data) => createSpace(data),
@ -83,7 +85,7 @@ export function useCreateSpaceMutation() {
queryClient.invalidateQueries({
queryKey: ["spaces"],
});
notifications.show({ message: "Space created successfully" });
notifications.show({ message: t("Space created successfully") });
},
onError: (error) => {
const errorMessage = error["response"]?.data?.message;
@ -105,11 +107,12 @@ export function useGetSpaceBySlugQuery(
export function useUpdateSpaceMutation() {
const queryClient = useQueryClient();
const { t } = useTranslation();
return useMutation<ISpace, Error, Partial<ISpace>>({
mutationFn: (data) => updateSpace(data),
onSuccess: (data, variables) => {
notifications.show({ message: "Space updated successfully" });
notifications.show({ message: t("Space updated successfully") });
const space = queryClient.getQueryData([
"space",
@ -134,11 +137,12 @@ export function useUpdateSpaceMutation() {
export function useDeleteSpaceMutation() {
const queryClient = useQueryClient();
const { t } = useTranslation();
return useMutation({
mutationFn: (data: Partial<ISpace>) => deleteSpace(data.id),
onSuccess: (data, variables) => {
notifications.show({ message: "Space deleted successfully" });
notifications.show({ message: t("Space deleted successfully") });
if (variables.slug) {
queryClient.removeQueries({
@ -176,11 +180,12 @@ export function useSpaceMembersQuery(
export function useAddSpaceMemberMutation() {
const queryClient = useQueryClient();
const { t } = useTranslation();
return useMutation<void, Error, IAddSpaceMember>({
mutationFn: (data) => addSpaceMember(data),
onSuccess: (data, variables) => {
notifications.show({ message: "Members added successfully" });
notifications.show({ message: t("Members added successfully") });
queryClient.invalidateQueries({
queryKey: ["spaceMembers", variables.spaceId],
});
@ -194,11 +199,12 @@ export function useAddSpaceMemberMutation() {
export function useRemoveSpaceMemberMutation() {
const queryClient = useQueryClient();
const { t } = useTranslation();
return useMutation<void, Error, IRemoveSpaceMember>({
mutationFn: (data) => removeSpaceMember(data),
onSuccess: (data, variables) => {
notifications.show({ message: "Removed successfully" });
notifications.show({ message: t("Member removed successfully") });
queryClient.invalidateQueries({
queryKey: ["spaceMembers", variables.spaceId],
});
@ -212,11 +218,12 @@ export function useRemoveSpaceMemberMutation() {
export function useChangeSpaceMemberRoleMutation() {
const queryClient = useQueryClient();
const { t } = useTranslation();
return useMutation<void, Error, IChangeSpaceMemberRole>({
mutationFn: (data) => changeMemberRole(data),
onSuccess: (data, variables) => {
notifications.show({ message: "Member role updated successfully" });
notifications.show({ message: t("Member role updated successfully") });
// due to pagination levels, change in cache instead
queryClient.refetchQueries({
queryKey: ["spaceMembers", variables.spaceId],