mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE): Move table slice into UI store and persist search
This commit is contained in:
@@ -34,7 +34,7 @@ import { useTableFilter } from '@/services/hooks/useTableFilter';
|
|||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import Badge from '@/components/Badge';
|
import Badge from '@/components/Badge';
|
||||||
import CheckboxInput from '@/components/input/CheckboxInput';
|
import CheckboxInput from '@/components/input/CheckboxInput';
|
||||||
import { useTableStore } from '@/stores/table/table.store';
|
import { useUiStore } from '@/stores/ui/ui.store';
|
||||||
import { BaseApproval, BaseApiResponse } from '@/types/api/api-general';
|
import { BaseApproval, BaseApiResponse } from '@/types/api/api-general';
|
||||||
|
|
||||||
const RowOptionsMenu = ({
|
const RowOptionsMenu = ({
|
||||||
@@ -351,7 +351,7 @@ const ApprovalHistoryModal = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const RecordingTable = () => {
|
const RecordingTable = () => {
|
||||||
const { searchValue, setSearchValue, resetSearchValue } = useTableStore();
|
const { searchValue, setSearchValue, resetSearchValue } = useUiStore();
|
||||||
const previousPathRef = useRef<string | null>(null);
|
const previousPathRef = useRef<string | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { create } from 'zustand';
|
|
||||||
import { devtools, persist } from 'zustand/middleware';
|
|
||||||
import { createTableSlice } from '@/stores/table/slices/table.slice';
|
|
||||||
import type { TableSlice } from '@/stores/table/slices/table.slice';
|
|
||||||
|
|
||||||
export type TableStore = TableSlice;
|
|
||||||
|
|
||||||
export const useTableStore = create<TableStore>()(
|
|
||||||
devtools(
|
|
||||||
persist(
|
|
||||||
(...args) => ({
|
|
||||||
...createTableSlice(...args),
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
name: 'table-cache',
|
|
||||||
partialize: (state) => ({
|
|
||||||
searchValue: state.searchValue,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
{
|
|
||||||
name: 'TableStore',
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
@@ -4,15 +4,18 @@ export interface TableState {
|
|||||||
searchValue: string;
|
searchValue: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableSlice {
|
export interface TableUISlice {
|
||||||
searchValue: string;
|
searchValue: string;
|
||||||
setSearchValue: (value: string) => void;
|
setSearchValue: (value: string) => void;
|
||||||
resetSearchValue: () => void;
|
resetSearchValue: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createTableSlice: StateCreator<TableSlice, [], [], TableSlice> = (
|
export const createTableUISlice: StateCreator<
|
||||||
set
|
TableUISlice,
|
||||||
) => ({
|
[],
|
||||||
|
[],
|
||||||
|
TableUISlice
|
||||||
|
> = (set) => ({
|
||||||
// Initial state
|
// Initial state
|
||||||
searchValue: '',
|
searchValue: '',
|
||||||
|
|
||||||
@@ -1,18 +1,28 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { devtools } from 'zustand/middleware';
|
import { devtools, persist } from 'zustand/middleware';
|
||||||
|
|
||||||
import { UIStore } from '@/types/stores';
|
import { UIStore } from '@/types/stores';
|
||||||
import { createMainUiSlice } from '@/stores/ui/slices/main.slice';
|
import { createMainUiSlice } from '@/stores/ui/slices/main.slice';
|
||||||
import { createDrawerUISlice } from '@/stores/ui/slices/drawer.slice';
|
import { createDrawerUISlice } from '@/stores/ui/slices/drawer.slice';
|
||||||
|
import { createTableUISlice } from '@/stores/ui/slices/table.slice';
|
||||||
|
|
||||||
export const useUiStore = create<UIStore>()(
|
export const useUiStore = create<UIStore>()(
|
||||||
devtools(
|
devtools(
|
||||||
(...args) => ({
|
persist(
|
||||||
...createMainUiSlice(...args),
|
(...args) => ({
|
||||||
...createDrawerUISlice(...args),
|
...createMainUiSlice(...args),
|
||||||
}),
|
...createDrawerUISlice(...args),
|
||||||
|
...createTableUISlice(...args),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
name: 'ui-cache',
|
||||||
|
partialize: (state) => ({
|
||||||
|
searchValue: state.searchValue,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
),
|
||||||
{
|
{
|
||||||
name: 'UIStore',
|
name: 'UIStore',
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+7
-1
@@ -26,7 +26,13 @@ type DrawerUISlice = {
|
|||||||
setIsNextStep: (v: boolean) => void;
|
setIsNextStep: (v: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UIStore = MainUiSlice & DrawerUISlice;
|
type TableUISlice = {
|
||||||
|
searchValue: string;
|
||||||
|
setSearchValue: (value: string) => void;
|
||||||
|
resetSearchValue: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UIStore = MainUiSlice & DrawerUISlice & TableUISlice;
|
||||||
|
|
||||||
type ProductionStandardFormSlice = {
|
type ProductionStandardFormSlice = {
|
||||||
formData: {
|
formData: {
|
||||||
|
|||||||
Reference in New Issue
Block a user