Newer
Older

Trygve Jørgensen
committed
<script lang="ts" setup>
import authInterceptor from '@/services/authInterceptor'
import type { Profile } from '@/types/profile'
import CardTemplate from '@/components/CardTemplate.vue'
import type { Challenge } from '@/types/challenge'
import type { Goal } from '@/types/goal'
import CardGoal from '@/components/CardGoal.vue'
import router from '@/router'
import SpareComponent from '@/components/SpareComponent.vue'
import { useUserStore } from '@/stores/userStore'
import ModalEditAvatar from '@/components/ModalEditAvatar.vue'
const profile = ref<Profile>()
const completedGoals = ref<Goal[]>([])
const completedChallenges = ref<Challenge[]>([])

Trygve Jørgensen
committed
const updateUser = async () => {
authInterceptor('/profile')
.then((response) => {
profile.value = response.data
console.log(profile.value)
})
.catch((error) => {
return console.log(error)
})
}
onMounted(async () => {
await updateUser()
await authInterceptor(`/goals/completed?page=0&size=3`)

Trygve Jørgensen
committed
.then((response) => {
completedGoals.value = response.data.content

Trygve Jørgensen
committed
})
.catch((error) => {

Trygve Jørgensen
committed
})
await authInterceptor('/challenges/completed?page=0&size=3')
.then((response) => {
completedChallenges.value = response.data.content
})
.catch((error) => {
return console.log(error)
})
const updateBiometrics = async () => {
await useUserStore().bioRegister()
await updateUser()
}
const updateProfilePicture = async () => {
await updateUser()
await userStore.getProfilePicture()
profilePicture.value = userStore.profilePicture
speech.value = [
`Velkommen, ${profile.value?.firstName} ${profile.value?.lastName} !`,
'Her kan du finne en oversikt over dine profilinstillinger!',
'Du kan også se dine fullførte sparemål og utfordringer!'
]

Trygve Jørgensen
committed
</script>
<div class="w-full flex px-10 justify-center">
<div class="flex flex-row flex-wrap justify-center w-full max-w-screen-xl gap-20">
<div class="flex flex-col max-w-96 w-full gap-5">
<img
:src="profilePicture"
alt="could not load"
class="block mx-auto h-32 rounded-full border-green-600 border-2 sm:mx-0 sm:shrink-0"
/>
<ModalEditAvatar @update-profile-picture="updateProfilePicture" />
<div class="w-full flex flex-col justify-between">
<h3 class="font-thin my-0">{{ profile?.username }}</h3>
<h3 class="font-thin my-0">
{{ profile?.firstName + ' ' + profile?.lastName }}
</h3>
<h3 class="font-thin my-0">{{ profile?.email }}</h3>
</div>
</div>
<h3
class="font-bold"
v-text="'Du har totalt spart ' + profile?.savedAmount + 'kr'"
/>
<p class="font-bold mx-3" v-text="'Brukskonto'" />
</div>
<p
class="mx-3"
v-text="profile?.spendingAccount.accNumber || 'Ingen brukskonto oppkoblet'"
/>
</CardTemplate>
<CardTemplate>
<p class="font-bold mx-3" v-text="'Sparekonto'" />
</div>
<p
class="mx-3"
v-text="profile?.savingAccount.accNumber || 'Ingen sparekonto oppkoblet'"
/>
</CardTemplate>
<button
Malin Haugland Høli
committed
class="primary secondary"
@click="router.push({ name: 'edit-profile' })"
v-text="'Rediger bruker'"
/>
<button
Malin Haugland Høli
committed
class="primary secondary"
@click="router.push({ name: 'edit-configuration' })"
v-text="'Rediger konfigurasjon'"
/>
<button class="primary" @click="updateBiometrics">
{{ profile?.hasPasskey ? 'Endre biometri' : 'Legg til biometri' }}
</button>
</div>
<div class="flex flex-col">
<SpareComponent
:speech="speech"
:png-size="15"
:imageDirection="'left'"
:direction="'right'"
class="mb-5"
></SpareComponent>
<div class="flex flex-row justify-between mx-4">
<p class="font-bold">Fullførte sparemål</p>
<a class="hover:p-0 cursor-pointer" v-text="'Se alle'" />
</div>
<CardTemplate class="p-4 flex flex-row flex-wrap justify-center gap-2 mb-4 mt-2">
<CardGoal v-for="goal in completedGoals" :key="goal.id" :goal-instance="goal" />
</CardTemplate>
<div class="flex flex-row justify-between mx-4">
<p class="font-bold">Fullførte utfordringer</p>
<a class="hover:p-0 cursor-pointer" v-text="'Se alle'" />
</div>
<CardTemplate class="p-4 flex flex-row flex-wrap justify-center gap-2 mb-4 mt-2">
<CardGoal
v-for="challenge in completedChallenges"
:key="challenge.id"
:goal-instance="challenge"
/>
</CardTemplate>
</div>
</div>
</div>