Adds edition of user profile
This commit is contained in:
@@ -13,6 +13,7 @@ export const useUserStore = defineStore(
|
||||
async (newValue) => {
|
||||
if (newValue) {
|
||||
await fetchCurrentUserProfile()
|
||||
await fetchCurrentCreatorProfile()
|
||||
} else {
|
||||
user.value = undefined
|
||||
creator.value = undefined
|
||||
@@ -31,10 +32,25 @@ export const useUserStore = defineStore(
|
||||
const hasCreator = computed(() =>
|
||||
creator.value
|
||||
&& Object.getOwnPropertyNames(creator.value).length >= 1)
|
||||
|
||||
|
||||
const fullname = computed(() => {
|
||||
if (user.value) {
|
||||
const {firstname, lastname} = user.value;
|
||||
|
||||
if (firstname && lastname) {
|
||||
return `${lastname}, ${firstname}`;
|
||||
} else if (firstname) {
|
||||
return firstname;
|
||||
} else if (lastname) {
|
||||
return lastname;
|
||||
}
|
||||
}
|
||||
return 'n/a';
|
||||
})
|
||||
|
||||
const alias = computed(() => {
|
||||
if (user.value) {
|
||||
return user.value.alias || `${user.value.firstName || ''} ${user.value.lastName || ''}`.trim() || 'Anonyme'
|
||||
return user.value.alias || `${user.value.firstname || ''} ${user.value.lastname || ''}`.trim() || 'Anonyme'
|
||||
}
|
||||
return 'Anonyme';
|
||||
})
|
||||
@@ -44,24 +60,120 @@ export const useUserStore = defineStore(
|
||||
: '/images/usersmedia/anonyme/profilepictures/profileAnonymeSquare.png'
|
||||
})
|
||||
|
||||
const client = useClient()
|
||||
|
||||
async function fetchCurrentUserProfile() {
|
||||
try {
|
||||
const client = useClient()
|
||||
const userResponse = await client.get("/api/GetMyUser");
|
||||
const userResponse = await client.get("/api/users/profile");
|
||||
user.value = userResponse.data
|
||||
|
||||
try {
|
||||
const creatorId = userResponse.data.id
|
||||
const creatorResponse = await client.get(`/api/creators/${creatorId}`)
|
||||
creator.value = creatorResponse.data
|
||||
} catch (error) {
|
||||
creator.value = undefined
|
||||
}
|
||||
} catch (error) {
|
||||
user.value = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchCurrentCreatorProfile() {
|
||||
try {
|
||||
const creatorResponse = await client.get(`/api/creators/profile`)
|
||||
creator.value = creatorResponse.data
|
||||
} catch (error) {
|
||||
creator.value = undefined
|
||||
}
|
||||
}
|
||||
|
||||
return {user, creator, alias, hasCreator, portraitUrl, fetchCurrentUserProfile}
|
||||
async function changeFullname(firstname, lastname) {
|
||||
try {
|
||||
await client.post(
|
||||
`/api/users/fullname`,
|
||||
{
|
||||
firstname: firstname,
|
||||
lastname: lastname
|
||||
})
|
||||
user.value.firstname = firstname;
|
||||
user.value.lastname = lastname;
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function changeAlias(alias) {
|
||||
try {
|
||||
await client.post(
|
||||
`/api/users/alias`,
|
||||
{
|
||||
alias: alias
|
||||
})
|
||||
user.value.alias = alias;
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function changeBirthday(birthdate) {
|
||||
try {
|
||||
await client.post(
|
||||
`/api/users/birthdate`,
|
||||
{
|
||||
birthdate: birthdate
|
||||
})
|
||||
user.value.birthDate = birthdate;
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function changePhone(phoneNumber) {
|
||||
try {
|
||||
await client.post(
|
||||
`/api/users/phone`,
|
||||
{
|
||||
phoneNumber: phoneNumber
|
||||
})
|
||||
user.value.phoneNumber = phoneNumber;
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function changeEmail(email) {
|
||||
try {
|
||||
await client.post(
|
||||
`/api/users/email`,
|
||||
{
|
||||
email: email
|
||||
})
|
||||
user.value.email = email;
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function changeAddress(address) {
|
||||
try {
|
||||
await client.post(
|
||||
`/api/users/address`,
|
||||
{
|
||||
address: address
|
||||
})
|
||||
user.value.address = address;
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
creator,
|
||||
alias,
|
||||
hasCreator,
|
||||
fullname,
|
||||
portraitUrl,
|
||||
changeFullname,
|
||||
changeAlias,
|
||||
changeBirthday,
|
||||
changePhone,
|
||||
changeEmail,
|
||||
changeAddress,
|
||||
fetchCurrentUserProfile,
|
||||
fetchCurrentCreatorProfile
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user