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