connected logout modal to api
This commit is contained in:
@@ -1,49 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
// imports
|
||||
|
||||
import useDeleteCartAll from "~/composables/api/orders/useDeleteCartAll";
|
||||
import { useAuth } from "~/composables/api/auth/useAuth";
|
||||
import useSignOut from "~/composables/api/auth/useSignOut";
|
||||
import { useToast } from "~/composables/global/useToast";
|
||||
import { QUERY_KEYS } from "~/constants";
|
||||
|
||||
// state
|
||||
|
||||
const { $queryClient: queryClient } = useNuxtApp();
|
||||
const router = useRouter();
|
||||
const { refreshToken, logout } = useAuth();
|
||||
const { addToast } = useToast();
|
||||
|
||||
const isShow = ref(false);
|
||||
|
||||
// queries
|
||||
|
||||
const { mutateAsync: deleteCartAll, isPending: deleteCartAllIsPending } =
|
||||
useDeleteCartAll();
|
||||
const { mutateAsync: signout, isPending: signoutIsPending } = useSignOut();
|
||||
|
||||
// methods
|
||||
|
||||
const handleSubmit = () => {
|
||||
deleteCartAll(undefined, {
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.cart] });
|
||||
isShow.value = false;
|
||||
addToast({
|
||||
message: "سبد با موفقیت حذف شد",
|
||||
options: {
|
||||
status: "success",
|
||||
},
|
||||
});
|
||||
setTimeout(() => {
|
||||
router.push({ name: "index" });
|
||||
}, 1000);
|
||||
},
|
||||
onError: () => {
|
||||
addToast({
|
||||
message: "خطایی در حذف سبد رخ داد",
|
||||
options: {
|
||||
status: "error",
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
signout(
|
||||
{ refresh_token: refreshToken.value! },
|
||||
{
|
||||
onSuccess: () => {
|
||||
addToast({
|
||||
message: "با موفقیت از حساب خارج شدید",
|
||||
});
|
||||
logout(true);
|
||||
},
|
||||
onError: () => {
|
||||
addToast({
|
||||
message: "خطایی در خروج از حساب رخ داد",
|
||||
});
|
||||
isShow.value = false;
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -78,10 +70,10 @@ const handleSubmit = () => {
|
||||
size="md"
|
||||
>
|
||||
<Icon
|
||||
v-if="deleteCartAllIsPending"
|
||||
v-if="signoutIsPending"
|
||||
name="svg-spinners:3-dots-bounce"
|
||||
/>
|
||||
<span v-else>آره; دارم میرم</span>
|
||||
<span v-else>آره دارم میرم</span>
|
||||
</Button>
|
||||
<DialogClose aria-label="Close">
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user