analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
103 lines (102 loc) • 2.78 kB
JavaScript
// src/components/AlertManager/useAlertForm.ts
import { create } from "zustand";
var initialState = {
title: "",
message: "",
image: null,
date: "",
time: "",
sendToday: false,
sendCopyToEmail: false,
recipientCategories: {}
};
var useAlertFormStore = create((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 = 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 = state.recipientCategories[key] ?? {
key,
label: key,
availableItems: [],
selectedIds: [],
allSelected: false
};
return {
recipientCategories: {
...state.recipientCategories,
[key]: { ...base, selectedIds, allSelected }
}
};
}),
clearCategorySelection: (key) => set((state) => {
const base = 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)
}));
export {
useAlertFormStore
};
//# sourceMappingURL=chunk-IQEDRSDD.mjs.map