Skip to content

Commit

Permalink
refactor: settings tanstack
Browse files Browse the repository at this point in the history
  • Loading branch information
FusiDaniel committed Oct 30, 2023
1 parent e43c8aa commit 6ef9068
Showing 1 changed file with 1 addition and 80 deletions.
81 changes: 1 addition & 80 deletions apps/container/src/views/Settings/SettingsView.vue
Original file line number Diff line number Diff line change
@@ -1,82 +1,3 @@
<script setup lang="ts">
import { ref, computed } from 'vue';
import { ElMessage } from 'element-plus';
import { CenteredLoading } from '@/components/CenteredLoading';
import useAuth from '@/store/useAuth';
import { useAliasInitials } from '@/utils/composables/aliasInitials';
import { Users, api } from 'services';
// dados do usuário
import { useQuery } from '@tanstack/vue-query';
const {
data: user,
isLoading: isLoadingUser,
error: isErrorUser,
} = useQuery({
queryKey: ['users', 'info'],
queryFn: userService.info,
select: (response) => response.data,
});
const userLogin = computed(() => {
return user.value?.email.replace('@aluno.ufabc.edu.br', '');
});
const addGoogleAccount = computed(() => {
const apiPath = api.defaults.baseURL?.replace('/v1', '');
return apiPath + 'connect/google?userId=' + user.value?._id;
});
const addFacebookAccount = computed(() => {
const apiPath = api.defaults.baseURL?.replace('/v1', '');
return apiPath + 'connect/facebook?userId=' + user.value?._id;
});
const createdAt = computed(() => {
if (user.value?.createdAt) {
const parsedDate = new Date(user.value.createdAt);
return parsedDate.toLocaleDateString('pt-BR', {
timeZone: 'UTC',
});
}
return ''; // Return a default value if createdAt is not defined
});
const userInitials = useAliasInitials();
// Modal
const dialog = ref(false);
// Lógica de remoção do usuário
const { logOut } = useAuth();
const handleLogout = () => {
logOut.value();
};
async function removeUser(): Promise<void> {
await Users.delete()
.then((res) => {
if (res.data) {
handleLogout();
}
})
.catch(() => {
ElMessage({
message: 'Ocorreu um erro ao tentar excluir sua conta',
type: 'error',
});
});
}
async function removeAccount() {
dialog.value = false;
await removeUser();
}
const reloadPage = () => window.location.reload();
// ---------------------------------------------------- //
</script>

<template>
<section>
<v-container>
Expand Down Expand Up @@ -354,4 +275,4 @@ const reloadPage = () => window.location.reload();
padding: 2px;
border-radius: 6px;
}
</style>
</style>

0 comments on commit 6ef9068

Please sign in to comment.