Skip to content

Commit

Permalink
Migrate ClientCreate.vue to composable api #248
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfausk committed Dec 28, 2024
1 parent 7cdbe5b commit 1c9c6b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
48 changes: 22 additions & 26 deletions web/assets/js/components/Clients/ClientCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,38 @@
/>
</template>

<script>
'use strict';
<script lang="ts">
import {defineComponent, ref} from 'vue';
import ClientForm from './ClientForm.vue';
import { useAlertStore, useClientStore } from '../../stores';
import {useAlertStore, useClientStore} from '../../stores';
import {ClientCreateRequest} from "@/js/model";
export default {
export default defineComponent({
name: 'ClientCreate',
components: {
ClientForm,
},
data: function () {
return {
alertStore: useAlertStore(),
clientStore: useClientStore(),
};
},
computed: {
currentUser() {
return this.authStore.currentUser;
},
},
async created() {
},
methods: {
async handleSubmit(payload) {
const client = await this.clientStore.createClient(payload);
setup() {
const clientForm = ref<InstanceType<typeof ClientForm> | null>(null);
const alertStore = useAlertStore();
const clientStore = useClientStore();
const handleSubmit = async (payload: ClientCreateRequest) => {
const client = await clientStore.createClient(payload);
if (client) {
this.alertStore.success(`Der Klient "${client.name}" wurde erfolgreich erstellt.`);
this.$refs.clientForm.resetForm();
alertStore.success(`Der Klient "${client.name}" wurde erfolgreich erstellt.`);
clientForm.value?.resetForm();
} else {
this.alertStore.error(`Klient erstellen fehlgeschlagen`, `Upps! :-(`);
alertStore.error('Klient erstellen fehlgeschlagen', 'Upps! :-(');
}
},
};
return {
clientForm,
handleSubmit,
};
},
};
});
</script>

<style scoped lang="scss">
Expand Down
5 changes: 5 additions & 0 deletions web/assets/js/components/Clients/ClientForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ function handleSubmit() {
emit('submit', client.value);
}
function resetForm() {
form.value?.reset();
setInitialValues();
}
async function updateRatingFile(file: File | null) {
client.value.ratingImageFileData = file ? await readFile(file) : null;
client.value.ratingImageFileName = file ? file.name : null;
Expand Down
4 changes: 3 additions & 1 deletion web/assets/js/components/Common/FormError.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<template>
<v-alert
v-if="hasError"
type="danger"
type="error"
class="mt-3 mb-0"
prominent
dense
>
<ul class="mb-0">
<li
Expand Down

0 comments on commit 1c9c6b8

Please sign in to comment.