feat: implement dynamic sidebar attribute injection based on selected campaign rule events and add UI component library.

This commit is contained in:
2026-07-14 19:15:29 +07:00
parent 628d87a55b
commit 19087ec1af
37 changed files with 5807 additions and 205 deletions

View File

@@ -1,5 +1,6 @@
import { createContext, useContext, useState } from "react";
import { createContext, useContext, useState, useEffect } from "react";
import type { ReactNode } from "react";
import type { Event } from "../types/event";
export type RuleCondition = {
id: string;
@@ -29,6 +30,9 @@ export type CampaignRuleState = {
};
formula: any;
notification: any;
availableEvents: Event[];
isLoadingEvents: boolean;
eventsError: string | null;
};
type CampaignRuleContextType = {
@@ -52,6 +56,9 @@ const initialState: CampaignRuleState = {
},
formula: {},
notification: {},
availableEvents: [],
isLoadingEvents: false,
eventsError: null,
};
const CampaignRuleContext = createContext<CampaignRuleContextType | undefined>(undefined);
@@ -60,6 +67,21 @@ export const CampaignRuleProvider = ({ children }: { children: ReactNode }) => {
const [state, setState] = useState<CampaignRuleState>(initialState);
const [currentStep, setCurrentStep] = useState(0);
useEffect(() => {
const fetchEvents = async () => {
setState((prev) => ({ ...prev, isLoadingEvents: true, eventsError: null }));
try {
const res = await fetch('/api/v1/events');
if (!res.ok) throw new Error('Failed to fetch events');
const data = await res.json();
setState((prev) => ({ ...prev, availableEvents: data, isLoadingEvents: false }));
} catch (err: any) {
setState((prev) => ({ ...prev, eventsError: err.message, isLoadingEvents: false }));
}
};
fetchEvents();
}, []);
const updateState = (section: keyof CampaignRuleState, payload: any) => {
setState((prev) => ({
...prev,