Decision now support auto mailing

This commit is contained in:
Simon Pocrnjič
2025-10-12 00:20:03 +02:00
parent 1b615163be
commit 3ab1c05fcc
33 changed files with 1862 additions and 548 deletions
@@ -8,7 +8,7 @@ import TextInput from "@/Components/TextInput.vue";
import CurrencyInput from "@/Components/CurrencyInput.vue";
import { useForm } from "@inertiajs/vue3";
import { FwbTextarea } from "flowbite-vue";
import { ref, watch } from "vue";
import { ref, watch, computed } from "vue";
const props = defineProps({
show: {
@@ -38,6 +38,7 @@ const form = useForm({
action_id: props.actions[0].id,
decision_id: props.actions[0].decisions[0].id,
contract_uuid: props.contractUuid,
send_auto_mail: true,
});
watch(
@@ -45,6 +46,8 @@ watch(
(action_id) => {
decisions.value = props.actions.filter((el) => el.id === action_id)[0].decisions;
form.decision_id = decisions.value[0].id;
// reset send flag on action change (will re-evaluate below)
form.send_auto_mail = true;
}
);
@@ -116,6 +119,41 @@ watch(
}
}
);
// Helper to read metadata for the currently selected decision
const currentDecision = () => decisions.value.find((d) => d.id === form.decision_id) || decisions.value[0];
const showSendAutoMail = () => {
const d = currentDecision();
return !!(d && d.auto_mail && d.email_template_id);
};
// Determine if the selected template requires a contract
const autoMailRequiresContract = computed(() => {
const d = currentDecision();
if (!d) return false;
const tmpl = d.email_template || d.emailTemplate || null;
const types = Array.isArray(tmpl?.entity_types) ? tmpl.entity_types : [];
return types.includes("contract");
});
// Disable checkbox when contract is required but none is selected
const autoMailDisabled = computed(() => {
return showSendAutoMail() && autoMailRequiresContract.value && !form.contract_uuid;
});
const autoMailDisabledHint = computed(() => {
return autoMailDisabled.value ? "Ta e-poštna predloga zahteva pogodbo. Najprej izberite pogodbo." : "";
});
// If disabled, force the flag off to avoid accidental queue attempts
watch(
() => autoMailDisabled.value,
(disabled) => {
if (disabled) {
form.send_auto_mail = false;
}
}
);
</script>
<template>
<DialogModal :show="show" @close="close">
@@ -179,6 +217,22 @@ watch(
placeholder="0,00"
/>
</div>
<div class="mt-2" v-if="showSendAutoMail()">
<div class="flex items-center justify-between">
<label class="flex items-center gap-2 text-sm">
<input
type="checkbox"
v-model="form.send_auto_mail"
:disabled="autoMailDisabled"
class="rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed"
>
<span>Send auto email</span>
</label>
</div>
<p v-if="autoMailDisabled" class="mt-1 text-xs text-amber-600">
{{ autoMailDisabledHint }}
</p>
</div>
<div class="flex justify-end mt-4">
<ActionMessage :on="form.recentlySuccessful" class="me-3">
Shranjuje.
+1
View File
@@ -257,6 +257,7 @@ const submitAttachSegment = () => {
:types="types"
tab-color="red-600"
:person="client_case.person"
/>
</div>
</div>