Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 51x 51x 51x 51x 51x | import { DialogProps } from "@mui/material";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import Alert from "components/Alert";
import Button from "components/Button";
import {
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
} from "components/Dialog";
import {
groupChatKey,
groupChatMessagesKey,
groupChatsListKey,
} from "features/queryKeys";
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import { RpcError } from "grpc-web";
import { useTranslation } from "i18n";
import { GLOBAL, MESSAGES } from "i18n/namespaces";
import React from "react";
import { service } from "service";
export default function LeaveDialog({
groupChatId,
...props
}: DialogProps & { groupChatId: number }) {
const { t } = useTranslation([GLOBAL, MESSAGES]);
const queryClient = useQueryClient();
const leaveGroupChatMutation = useMutation<Empty, RpcError, void>({
mutationFn: () => service.conversations.leaveGroupChat(groupChatId),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [groupChatMessagesKey(groupChatId)],
});
queryClient.invalidateQueries({
queryKey: [groupChatsListKey],
});
queryClient.invalidateQueries({
queryKey: [groupChatKey(groupChatId)],
});
Iif (props.onClose) props.onClose({}, "escapeKeyDown");
},
});
const handleLeaveGroupChat = () => leaveGroupChatMutation.mutate();
return (
<Dialog {...props} aria-labelledby="leave-dialog-title">
<DialogTitle id="leave-dialog-title">
{t("messages:leave_chat_dialog.title")}
</DialogTitle>
<DialogContent>
{leaveGroupChatMutation.error && (
<Alert severity="error">
{leaveGroupChatMutation.error?.message}
</Alert>
)}
<DialogContentText>
{t("messages:leave_chat_dialog.message")}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button
onClick={handleLeaveGroupChat}
loading={leaveGroupChatMutation.isPending}
>
{t("global:yes")}
</Button>
<Button
onClick={() =>
props.onClose ? props.onClose({}, "escapeKeyDown") : null
}
loading={leaveGroupChatMutation.isPending}
>
{t("global:no")}
</Button>
</DialogActions>
</Dialog>
);
}
|