-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(dashboard/user-overview): refactored create user form (#324)
* refactor(dashboard/user-overview): refactored create user form * fix(dashboard/user-overview): re-added code that was thought to be unused * refactor(dashboard/user-create-form): some small code changes
- Loading branch information
1 parent
cc2d7b5
commit 9975799
Showing
6 changed files
with
152 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
apps/dashboard/src/modules/admin/components/users/forms/UserCreateForm.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<template> | ||
<div class="flex flex-column gap-2"> | ||
<InputSpan :label="t('userDetails.First name')" | ||
:value="form.model.firstName.value.value" | ||
:attributes="form.model.firstName.attr.value" | ||
@update:value="form.context.setFieldValue('firstName', $event)" | ||
:errors="form.context.errors.value.firstName" | ||
:disabled="!edit" | ||
id="name" :placeholder="t('userDetails.First name')" type="text" /> | ||
<InputSpan :label="t('userDetails.Last name')" | ||
:value="form.model.lastName?.value.value" | ||
:attributes="form.model.lastName?.attr.value" | ||
@update:value="form.context.setFieldValue('lastName', $event)" | ||
:errors="form.context.errors.value.lastName" | ||
:disabled="!edit" | ||
id="name" placeholder="Doe" type="text" /> | ||
<InputSpan :label="t('userDetails.Nickname')" | ||
:value="form.model.nickname?.value.value || undefined" | ||
:attributes="form.model.nickname?.attr.value" | ||
@update:value="form.context.setFieldValue('nickname', $event)" | ||
:errors="form.context.errors.value.nickname" | ||
:disabled="!edit" | ||
id="name" :placeholder="t('userDetails.Nickname')" type="text" /> | ||
<InputSpan | ||
:label="t('userDetails.Email address')" | ||
:value="form.model.email?.value.value" | ||
:attributes="form.model.email?.attr.value" | ||
@update:value="form.context.setFieldValue('email', $event)" | ||
:errors="form.context.errors.value.email" | ||
:disabled="!edit" | ||
id="name" placeholder="[email protected]" type="text" /> | ||
<InputSpan :label="t('userDetails.Usertype')" | ||
:value="form.model.userType?.value.value" | ||
:attributes="form.model.userType?.attr.value" | ||
@update:value="form.context.setFieldValue('userType', $event)" | ||
:errors="form.context.errors.value.userType" | ||
id="name" :placeholder="t('userDetails.Usertype')" type="usertype"/> | ||
<InputSpan :label="t('profile.ofAge')" | ||
:value="form.model.ofAge?.value.value" | ||
:attributes="form.model.ofAge?.attr.value" | ||
@update:value="form.context.setFieldValue('ofAge', $event)" | ||
:errors="form.context.errors.value.ofAge" | ||
:disabled="!edit" | ||
id="name" :placeholder="t('profile.ofAge')" type="boolean"/> | ||
<InputSpan :label="t('profile.canGoIntoDebt')" | ||
:value="form.model.canGoIntoDebt?.value.value" | ||
:attributes="form.model.canGoIntoDebt?.attr.value" | ||
@update:value="form.context.setFieldValue('canGoIntoDebt', $event)" | ||
:errors="form.context.errors.value.canGoIntoDebt" | ||
:disabled="!edit" | ||
id="name" :placeholder="t('profile.canGoIntoDebt')" type="boolean"/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import InputSpan from "@/components/InputSpan.vue"; | ||
import { useI18n } from "vue-i18n"; | ||
import { useToast } from "primevue/usetoast"; | ||
import { type Form, setSubmit } from "@/utils/formUtils"; | ||
import type { CreateUserRequest } from "@sudosos/sudosos-client"; | ||
import { type PropType } from "vue"; | ||
import { createUserSchema } from "@/utils/validation-schema"; | ||
import * as yup from "yup"; | ||
import apiService from "@/services/ApiService"; | ||
import { handleError } from "@/utils/errorUtils"; | ||
const { t } = useI18n(); | ||
const toast = useToast(); | ||
const emit = defineEmits(['update:edit']); | ||
const props = defineProps({ | ||
form: { | ||
type: Object as PropType<Form<yup.InferType<typeof createUserSchema>>>, | ||
required: true, | ||
}, | ||
edit: { | ||
type: Boolean, | ||
required: false, | ||
default: true, | ||
}, | ||
}); | ||
setSubmit(props.form, props.form.context.handleSubmit(async (values) => { | ||
const createUserRequest: CreateUserRequest = { | ||
...values, | ||
email: values.email || '', | ||
nickname: values.nickname || '', | ||
type: values.userType, | ||
ofAge: values.ofAge, | ||
canGoIntoDebt: values.canGoIntoDebt, | ||
}; | ||
await apiService.user.createUser(createUserRequest).then(() => { | ||
toast.add({ | ||
severity: 'success', | ||
summary: t('successMessages.success'), | ||
detail: t('successMessages.userUpdated'), | ||
life: 3000, | ||
}); | ||
emit('update:edit', false); | ||
}).catch((error) => { | ||
handleError(error, toast); | ||
}); | ||
})); | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters