UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

103 lines (100 loc) 3.07 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/components/AlertManager/useAlertForm.ts var _zustand = require('zustand'); var initialState = { title: "", message: "", image: null, date: "", time: "", sendToday: false, sendCopyToEmail: false, recipientCategories: {} }; var useAlertFormStore = _zustand.create.call(void 0, (set) => ({ ...initialState, // Step 1 - Mensagem setTitle: (title) => set({ title }), setMessage: (message) => set({ message }), setImage: (image) => set({ image }), // Step 2 - Destinatários (Dinâmico) initializeCategory: (category) => set((state) => ({ recipientCategories: { ...state.recipientCategories, [category.key]: { ...category, selectedIds: category.selectedIds || [], allSelected: category.allSelected || false } } })), updateCategoryItems: (key, items) => set((state) => { const base = _nullishCoalesce(state.recipientCategories[key], () => ( { key, label: key, availableItems: [], selectedIds: [], allSelected: false })); return { recipientCategories: { ...state.recipientCategories, [key]: { ...base, availableItems: items } } }; }), updateCategorySelection: (key, selectedIds, allSelected) => set((state) => { const base = _nullishCoalesce(state.recipientCategories[key], () => ( { key, label: key, availableItems: [], selectedIds: [], allSelected: false })); return { recipientCategories: { ...state.recipientCategories, [key]: { ...base, selectedIds, allSelected } } }; }), clearCategorySelection: (key) => set((state) => { const base = _nullishCoalesce(state.recipientCategories[key], () => ( { key, label: key, availableItems: [], selectedIds: [], allSelected: false })); return { recipientCategories: { ...state.recipientCategories, [key]: { ...base, selectedIds: [], allSelected: false } } }; }), // Step 3 - Data de envio setDate: (date) => set({ date }), setTime: (time) => set({ time }), setSendToday: (sendToday) => { if (!sendToday) { set({ sendToday, date: "", time: "" }); return; } const now = /* @__PURE__ */ new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, "0"); const day = String(now.getDate()).padStart(2, "0"); const hours = String(now.getHours()).padStart(2, "0"); const minutes = String(now.getMinutes()).padStart(2, "0"); set({ sendToday, date: `${year}-${month}-${day}`, time: `${hours}:${minutes}` }); }, setSendCopyToEmail: (sendCopyToEmail) => set({ sendCopyToEmail }), // Reset form resetForm: () => set(initialState) })); exports.useAlertFormStore = useAlertFormStore; //# sourceMappingURL=chunk-TBD2B4VV.js.map