feat(FE): add state filter dashboard with store

This commit is contained in:
randy-ar
2026-01-18 19:30:54 +07:00
parent a9c22d778b
commit 55b50d4184
8 changed files with 132 additions and 21 deletions
+24
View File
@@ -0,0 +1,24 @@
'use client';
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { createDashboardFilterSlice } from '@/stores/dashboard/slices/dashboard-filter.slice';
import { DashboardFilterSlice } from '@/types/stores';
export type DashboardStore = DashboardFilterSlice;
export const useDashboardStore = create<DashboardStore>()(
devtools(
persist(
(...args) => ({
...createDashboardFilterSlice(...args),
}),
{
name: 'dashboard-filter-cache',
}
),
{
name: 'DashboardStore',
}
)
);
+2
View File
@@ -0,0 +1,2 @@
export { useDashboardStore } from './dashboard.store';
export type { DashboardStore } from './dashboard.store';
@@ -0,0 +1,45 @@
import { DashboardFilterSlice } from '@/types/stores';
import { StateCreator } from 'zustand';
export const createDashboardFilterSlice: StateCreator<
DashboardFilterSlice,
[],
[],
DashboardFilterSlice
> = (set) => ({
// Initial state
filterValues: {
startDate: '',
endDate: '',
analysisMode: 'OVERVIEW',
comparisonType: undefined,
location: [],
locationIds: undefined,
flock: undefined,
flockIds: undefined,
kandang: undefined,
kandangIds: undefined,
},
// Actions
setFilterValues: (values) => set({ filterValues: values }),
resetFilterValues: () => {
alert('reset filter values');
return set({
filterValues: {
startDate: '',
endDate: '',
analysisMode: 'OVERVIEW',
comparisonType: undefined,
location: [],
locationIds: undefined,
flock: undefined,
flockIds: undefined,
kandang: undefined,
kandangIds: undefined,
},
});
},
});