mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 23:05:46 +00:00
feat(FE): add state filter dashboard with store
This commit is contained in:
@@ -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',
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -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,
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user