Merge pull request 'refactor: refs #8372 update FormModelPopup to use props for save and continue logic' (!1477) from 8372-warmfix-saveAndContinue into test
Reviewed-on: #1477 Reviewed-by: Pablo Natek <pablone@verdnatura.es> Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
498c351c51
|
@ -1,12 +1,13 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue';
|
import { ref, computed, useAttrs, nextTick } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { useState } from 'src/composables/useState';
|
||||||
|
|
||||||
import FormModel from 'components/FormModel.vue';
|
import FormModel from 'components/FormModel.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['onDataSaved', 'onDataCanceled']);
|
const emit = defineEmits(['onDataSaved', 'onDataCanceled']);
|
||||||
|
|
||||||
defineProps({
|
const props = defineProps({
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -22,12 +23,21 @@ defineProps({
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const attrs = useAttrs();
|
||||||
|
const state = useState();
|
||||||
const formModelRef = ref(null);
|
const formModelRef = ref(null);
|
||||||
const closeButton = ref(null);
|
const closeButton = ref(null);
|
||||||
const isSaveAndContinue = ref(false);
|
const isSaveAndContinue = ref(props.showSaveAndContinueBtn);
|
||||||
const onDataSaved = (formData, requestResponse) => {
|
const isLoading = computed(() => formModelRef.value?.isLoading);
|
||||||
if (closeButton.value && !isSaveAndContinue.value) closeButton.value.click();
|
const reset = computed(() => formModelRef.value?.reset);
|
||||||
|
|
||||||
|
const onDataSaved = async (formData, requestResponse) => {
|
||||||
|
if (!isSaveAndContinue.value) closeButton.value?.click();
|
||||||
|
if (isSaveAndContinue.value) {
|
||||||
|
await nextTick();
|
||||||
|
state.set(attrs.model, attrs.formInitialData);
|
||||||
|
}
|
||||||
|
isSaveAndContinue.value = props.showSaveAndContinueBtn;
|
||||||
emit('onDataSaved', formData, requestResponse);
|
emit('onDataSaved', formData, requestResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,9 +46,6 @@ const onClick = async (saveAndContinue) => {
|
||||||
await formModelRef.value.save();
|
await formModelRef.value.save();
|
||||||
};
|
};
|
||||||
|
|
||||||
const isLoading = computed(() => formModelRef.value?.isLoading);
|
|
||||||
const reset = computed(() => formModelRef.value?.reset);
|
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
isLoading,
|
isLoading,
|
||||||
onDataSaved,
|
onDataSaved,
|
||||||
|
@ -74,10 +81,7 @@ defineExpose({
|
||||||
data-cy="FormModelPopup_cancel"
|
data-cy="FormModelPopup_cancel"
|
||||||
v-close-popup
|
v-close-popup
|
||||||
z-max
|
z-max
|
||||||
@click="
|
@click="emit('onDataCanceled')"
|
||||||
isSaveAndContinue = false;
|
|
||||||
emit('onDataCanceled');
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
<QBtn
|
<QBtn
|
||||||
:flat="showSaveAndContinueBtn"
|
:flat="showSaveAndContinueBtn"
|
||||||
|
|
|
@ -961,14 +961,6 @@ function cardClick(_, row) {
|
||||||
transition-show="scale"
|
transition-show="scale"
|
||||||
transition-hide="scale"
|
transition-hide="scale"
|
||||||
:full-width="createComplement?.isFullWidth ?? false"
|
:full-width="createComplement?.isFullWidth ?? false"
|
||||||
@before-hide="
|
|
||||||
() => {
|
|
||||||
if (createRef.isSaveAndContinue) {
|
|
||||||
showForm = true;
|
|
||||||
createForm.formInitialData = { ...create.formInitialData };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"
|
|
||||||
data-cy="vn-table-create-dialog"
|
data-cy="vn-table-create-dialog"
|
||||||
>
|
>
|
||||||
<FormModelPopup
|
<FormModelPopup
|
||||||
|
|
Loading…
Reference in New Issue