-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathUserUpdateForm.vue
60 lines (53 loc) · 1.31 KB
/
UserUpdateForm.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
<div v-show="userPending">(Chargement)</div>
<form v-if="!userPending" @submit.prevent.stop="updateUser">
<h1>Update user {{ data.email }}</h1>
<UserForm
v-model:email="localReactive.email"
v-model:password="password"
v-model:password-confirm="passwordConfirm"
:is-password-confirmed="isPasswordConfirmed"
/>
{{ errorMessage }}
{{ error }}
<button type="submit">Save</button>
</form>
</template>
<script setup lang="ts">
import useGetUser from "~/composables/api/user/useGetUser";
import useUpdateUser from "~/composables/api/user/useUpdateUser";
import useUser from "~/composables/user/useUser";
const props = defineProps<{
userId: string;
}>();
const { errorMessage, updateUser: updateUserApi } = useUpdateUser();
const {
data,
error,
pending: userPending,
refresh: userRefresh,
} = await useGetUser(props.userId as string);
const {
localReactive,
password,
passwordConfirm,
isPasswordConfirmed,
securedPassword,
} = useUser(data);
const updateUser = async () => {
try {
await updateUserApi(
data.value.id,
{
email: localReactive.email,
},
securedPassword.value
);
userRefresh();
await navigateTo("/users");
} catch (e) {
logger.error(e);
}
};
</script>
<style scoped lang="scss"></style>