UNPKG

@agendize/vue-settings

Version:
138 lines (137 loc) 7.77 kB
import { defineComponent as J, ref as E, onMounted as K, watch as Q, openBlock as T, createBlock as U, unref as b, withCtx as C, createVNode as w, createCommentVNode as X } from "vue"; import { StructuredLayout as Y, StructuredSection as j } from "@agendize/design-system"; import { u as Z } from "./vendor.26bbd9f1.js"; import { FormGenerator as M, FormItemEntityExtended as N } from "@agendize/vue-form"; import { FormItemEntity as F } from "@agendize/js-calendar-api"; import { useApi as ee, useAccountStore as ne, defineAsyncComponentWithLoading as le } from "@agendize/vue-tools"; import { useToast as ie } from "vue-toastification"; const ue = /* @__PURE__ */ J({ __name: "ConferenceForm", props: { organisation: {}, conference: {} }, emits: ["hasChange", "valid"], setup(P, { expose: R, emit: W }) { const m = P, { t: o, locale: oe } = Z(); ee(), ne(); const q = ie(), y = W, u = E([]), v = E([]); E(!1); function _() { var h, p, r, t, s, d, x, G, $, S, A, I, k, B, L, D, O; const n = (h = u.value) == null ? void 0 : h.find((c) => c.bind === "crm-email"), e = (p = u.value) == null ? void 0 : p.find((c) => c.bind === "crm-phone"), l = (r = u.value) == null ? void 0 : r.find((c) => c.bind === "crm-last-name"), i = (t = u.value) == null ? void 0 : t.find((c) => c.bind === "crm-first-name"), a = []; if (!(l != null && l.required) || !(i != null && i.required)) { const c = []; l != null && l.required || c.push((s = l == null ? void 0 : l.label) != null ? s : o("common.field.lastName.label")), i != null && i.required || c.push((d = i == null ? void 0 : i.label) != null ? d : o("common.field.firstName.label")), a.push({ label: o("settings.conferences.details.forms.errors.must-be-required"), fieldNames: c }); } !(n != null && n.required) && !(e != null && e.required) && a.push({ label: o("settings.conferences.details.forms.errors.email-or-phone-required"), fieldNames: [(x = n == null ? void 0 : n.label) != null ? x : o("common.field.email.label"), (G = e == null ? void 0 : e.label) != null ? G : o("common.field.phone.label")] }); const f = []; !!(n != null && n.required) && !(n != null && n.visible) && f.push(($ = n.label) != null ? $ : o("common.field.email.label")), !!(e != null && e.required) && !(e != null && e.visible) && f.push((S = e.label) != null ? S : o("common.field.phone.label")), !!(l != null && l.required) && !(l != null && l.visible) && f.push((A = l.label) != null ? A : o("common.field.lastName.label")), !!(i != null && i.required) && !(i != null && i.visible) && f.push((I = i.label) != null ? I : o("common.field.firstName.label")), f.length > 0 && a.push({ label: o("settings.conferences.details.forms.errors.required-and-not-visible"), fieldNames: f }); const g = le(() => import("./ConferenceFormError.081e2d4d.js")); if (a.length > 0) { q == null || q.error({ component: g, props: { presentationLabel: o("settings.conferences.details.forms.errors.multiple"), errors: a } }); return; } return { id: (L = (B = (k = m.conference) == null ? void 0 : k.form) == null ? void 0 : B.id) != null ? L : "", name: (O = (D = m.conference) == null ? void 0 : D.name) != null ? O : "", contactFields: u.value, additionalFields: [v.value] }; } function z(n) { var l; const e = new N(); return Object.assign(e, n), ["crm-first-name", "crm-last-name"].indexOf((l = n.bind) != null ? l : "") >= 0 && (e.hiddenProps = ["required"]), e; } function V(n, e) { u.value = (n != null ? n : []).map(z), v.value = (e != null ? e : [[]]).flat(); } function H() { var l, i, a, f, g, h; if (!m.organisation.email) return; let n = [], e = [[]]; if (!m.conference.id || ((i = (l = m.conference.form) == null ? void 0 : l.contactFields) != null ? i : []).length === 0) { const p = new Date().getDate(), r = new F(); r.bind = "crm-first-name", r.bindGroup = "crm", r.required = !0, r.visible = !0, r.label = o("common.field.firstName.label"), r.placeholder = o("common.field.firstName.placeholder"), r.type = "input", r.id = `${p + 1}`, n.push(r); const t = new F(); t.bind = "crm-last-name", t.bindGroup = "crm", t.required = !0, t.visible = !0, t.label = o("common.field.lastName.label"), t.placeholder = o("common.field.lastName.placeholder"), t.type = "input", t.id = `${p + 2}`, n.push(t); const s = new F(); s.bind = "crm-email", s.bindGroup = "crm", s.required = !0, s.visible = !0, s.label = o("common.field.email.label"), s.placeholder = o("common.field.email.placeholder"), s.type = "email", s.id = `${p + 3}`, n.push(s); const d = new F(); d.bind = "crm-phone", d.bindGroup = "crm", d.required = !0, d.visible = !0, d.label = o("common.field.phone.label"), d.placeholder = o("common.field.phone.placeholder"), d.type = "phone", d.id = `${p + 4}`, n.push(d); } else n = (f = (a = m.conference.form) == null ? void 0 : a.contactFields) != null ? f : [], e = (h = (g = m.conference.form) == null ? void 0 : g.additionalFields) != null ? h : [[]]; V(n, e); } return K(() => { H(), y("valid", !0); }), Q(() => m.conference, (n) => { var e, l, i, a; V((l = (e = n.form) == null ? void 0 : e.contactFields) != null ? l : [], (a = (i = n.form) == null ? void 0 : i.additionalFields) != null ? a : [[]]); }, { deep: !0 }), R({ getConferenceFormBeforeSave: _ }), (n, e) => (T(), U(b(Y), null, { column1: C(() => [ w(b(j), { title: { label: b(o)("settings.conferences.details.forms.section.contact.title") }, "sub-title": { label: b(o)("settings.conferences.details.forms.section.contact.sub-title") } }, { content: C(() => { var l; return [ u.value.length >= 0 ? (T(), U(b(M), { key: 0, id: `conference-forms-main-${(l = m.conference) == null ? void 0 : l.id}`, dragEnable: !1, addEnable: !1, deleteEnable: !1, editEnable: !0, version: "2", modelValue: u.value, "onUpdate:modelValue": [ e[0] || (e[0] = (i) => u.value = i), e[1] || (e[1] = () => { y("hasChange"); }) ] }, null, 8, ["id", "modelValue"])) : X("", !0) ]; }), _: 1 }, 8, ["title", "sub-title"]), w(b(j), { title: { label: b(o)("settings.conferences.details.forms.section.additional.title") }, "sub-title": { label: b(o)("settings.conferences.details.forms.section.additional.sub-title") } }, { content: C(() => { var l; return [ w(b(M), { id: `conference-forms-additional-${(l = m.conference) == null ? void 0 : l.id}`, dragEnable: !0, addEnable: !0, deleteEnable: !0, editEnable: !0, dragGroup: "additional-fields", version: "2", hidden: { types: ["name", "file", "rating"] }, modelValue: v.value, "onUpdate:modelValue": [ e[2] || (e[2] = (i) => v.value = i), e[3] || (e[3] = () => { y("hasChange"); }) ] }, null, 8, ["id", "modelValue"]) ]; }), _: 1 }, 8, ["title", "sub-title"]) ]), _: 1 })); } }); export { ue as default };