Skip to content

Commit

Permalink
chore(vue) add confirm password check on register
Browse files Browse the repository at this point in the history
  • Loading branch information
lakardion committed Nov 21, 2024
1 parent 2ce10d0 commit bf2c7d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { useAlert } from '@/composables/CommonAlerts'
import { MustMatchValidator } from '@thinknimble/tn-forms'

export function useUsers() {
const userStore = useUserStore()
Expand All @@ -27,6 +28,13 @@ export function useUsers() {
const forgotPasswordForm = reactive(new EmailForgotPasswordForm({}) as TEmailForgotPasswordForm)
const resetPasswordForm = reactive(new ResetPasswordForm({}) as TResetPasswordForm)
const registerForm = reactive(new AccountForm({}) as TAccountForm)
registerForm.addFormLevelValidator(
'confirmPassword',
new MustMatchValidator({
matcher: 'password',
message: 'Passwords must match',
}),
)
const loading = ref(false)
const { errorAlert, successAlert } = useAlert()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@ export class ResetPasswordForm extends Form<ResetPasswordInput> {
value: '',
validators: [],
})

static dynamicValidators = {
confirmPassword: [
new MustMatchValidator({
matcher: 'password',
}),
],
}
}

export type TResetPasswordForm = ResetPasswordForm & ResetPasswordInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import InputField from '@/components/inputs/InputField.vue'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
import { useUsers } from '@/composables/use-users'
import Button from '@/components/Button.vue'
const { register, loading, registerForm: form } = useUsers()
const onRegister = () => {
const createAccountInput = {
Expand Down Expand Up @@ -89,7 +91,13 @@ const onRegister = () => {
</div>
<div>
<LoadingSpinner v-if="loading" />
<Button variant="primary" v-else :disabled="!form.isValid" type="submit">
<Button
variant="primary"
v-else
:disabled="!form.isValid"
extend-class="w-full"
type="submit"
>
Sign up
</Button>
</div>
Expand Down

0 comments on commit bf2c7d5

Please sign in to comment.