|
1 | 1 | <template> |
2 | | - <div> |
3 | | - <label for="email">{{ $t("components.user.form.email") }}</label> |
4 | | - <input |
5 | | - type="text" |
6 | | - :value="email" |
7 | | - @input="$emit('update:email', clearInput($event))" |
8 | | - /> |
9 | | - </div> |
10 | | - <div> |
11 | | - <label for="password">{{ $t("components.user.form.password") }}</label> |
12 | | - <input |
13 | | - name="password" |
14 | | - type="password" |
15 | | - :value="password" |
16 | | - @input="$emit('update:password', clearInput($event))" |
17 | | - /> |
18 | | - </div> |
19 | | - <div> |
20 | | - <label for="passwordConfirm">{{ |
21 | | - $t("components.user.form.passwordConfirm") |
22 | | - }}</label> |
23 | | - <input |
24 | | - name="passwordConfirm" |
25 | | - type="password" |
26 | | - :value="passwordConfirm" |
27 | | - @input="$emit('update:passwordConfirm', clearInput($event))" |
28 | | - /> |
29 | | - <span v-if="!isPasswordConfirmed" class="text-danger"> |
30 | | - {{ $t("components.user.form.errorPasswordConfirm") }} |
31 | | - </span> |
| 2 | + <div class="grid"> |
| 3 | + <div class="col-12"> |
| 4 | + <form @submit.prevent.stop="submit"> |
| 5 | + <div class="field col-12"> |
| 6 | + <span class="p-float-label"> |
| 7 | + <InputText |
| 8 | + id="user-email" |
| 9 | + v-model="state.email" |
| 10 | + type="text" |
| 11 | + :placeholder="$t('components.user.form.email')" |
| 12 | + /> |
| 13 | + <label for="user-email">{{ |
| 14 | + $t("components.user.form.email") |
| 15 | + }}</label> |
| 16 | + </span> |
| 17 | + </div> |
| 18 | + <div class="field col-12"> |
| 19 | + <FormRegisterPasswordInput |
| 20 | + v-model="password" |
| 21 | + input-id="user-password" |
| 22 | + /> |
| 23 | + </div> |
| 24 | + <div class="field col-12"> |
| 25 | + <FormRegisterPasswordInput |
| 26 | + v-model="passwordConfirm" |
| 27 | + input-id="user-passwordConfirm" |
| 28 | + > |
| 29 | + {{ $t("components.user.form.passwordConfirm") }} |
| 30 | + </FormRegisterPasswordInput> |
| 31 | + </div> |
| 32 | + <div v-show="!isPasswordConfirmed"> |
| 33 | + {{ $t("components.user.form.errorPasswordConfirm") }} |
| 34 | + </div> |
| 35 | + <div> |
| 36 | + <slot name="buttons" :is-valid="isValid" :cancel="cancel"> |
| 37 | + <Button |
| 38 | + type="button" |
| 39 | + severity="danger" |
| 40 | + class="mr-2 mb-2" |
| 41 | + @click="cancel" |
| 42 | + > |
| 43 | + {{ $t("components.user.form.buttonCancel") }} |
| 44 | + </Button> |
| 45 | + <Button type="submit" :disabled="!isValid" class="mr-2 mb-2"> |
| 46 | + {{ $t("components.user.form.ok") }} |
| 47 | + </Button> |
| 48 | + </slot> |
| 49 | + </div> |
| 50 | + </form> |
| 51 | + </div> |
32 | 52 | </div> |
33 | 53 | </template> |
34 | 54 | <script setup lang="ts"> |
35 | 55 | import type { User } from "~/types/User"; |
36 | 56 |
|
37 | | -defineProps< |
38 | | - Omit<User, "id"> & { |
39 | | - isPasswordConfirmed: boolean; |
40 | | - password: string; |
41 | | - passwordConfirm: string; |
42 | | - } |
43 | | ->(); |
44 | | -interface EventEmitter { |
45 | | - (e: "update:email", email: string): void; |
46 | | - (e: "update:password", password: string): void; |
47 | | - (e: "update:passwordConfirm", passwordConfirm: string): void; |
| 57 | +interface Props { |
| 58 | + defaultValue: Omit<User, "id">; |
48 | 59 | } |
| 60 | +const props = withDefaults(defineProps<Props>(), { |
| 61 | + defaultValue() { |
| 62 | + return { |
| 63 | + email: "", |
| 64 | + }; |
| 65 | + }, |
| 66 | +}); |
| 67 | +const state = reactive({ ...props.defaultValue }); |
| 68 | +const password = ref(""); |
| 69 | +const passwordConfirm = ref(""); |
| 70 | +
|
| 71 | +const isPasswordConfirmed = computed( |
| 72 | + () => password.value === passwordConfirm.value |
| 73 | +); |
49 | 74 |
|
50 | | -defineEmits<EventEmitter>(); |
| 75 | +const isPasswordEmpty = computed(() => !password.value); |
| 76 | +const securedPassword = computed(() => |
| 77 | + isPasswordConfirmed && isPasswordEmpty ? password.value : "" |
| 78 | +); |
| 79 | +const isValid = isPasswordConfirmed; |
51 | 80 |
|
52 | | -const clearInput = (inputEvent: Event) => { |
53 | | - return (inputEvent.target as HTMLInputElement)?.value || ""; |
| 81 | +interface EventEmitter { |
| 82 | + ( |
| 83 | + e: "submit", |
| 84 | + value: Omit<User, "id"> & { |
| 85 | + password: string; |
| 86 | + } |
| 87 | + ): void; |
| 88 | + (e: "cancel"): void; |
| 89 | +} |
| 90 | +
|
| 91 | +const emits = defineEmits<EventEmitter>(); |
| 92 | +const submit = () => { |
| 93 | + emits("submit", { ...state, password: securedPassword.value }); |
| 94 | +}; |
| 95 | +const cancel = () => { |
| 96 | + emits("cancel"); |
54 | 97 | }; |
55 | 98 | </script> |
56 | 99 |
|
|
0 commit comments