Compare commits
No commits in common. "04e28bce1a601416c829ad5f816dd48d43d73b92" and "3826f40048b61d07674ce6bd0a79b889fb1dbae6" have entirely different histories.
04e28bce1a
...
3826f40048
@ -1,4 +1,5 @@
|
||||
import type { RightPanelMode } from "@repo/rdx-ui/hooks";
|
||||
import { useMemo } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
|
||||
import { useCustomerSummaryPanelController } from "./use-customer-summary-panel.controller";
|
||||
@ -6,15 +7,38 @@ import { useListCustomersController } from "./use-list-customers.controller";
|
||||
|
||||
export const useListCustomersPageController = () => {
|
||||
const listCtrl = useListCustomersController();
|
||||
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const customerId = searchParams.get("customerId") ?? "";
|
||||
const panelMode = (searchParams.get("panel") as RightPanelMode | null) ?? "view";
|
||||
// -----------------------------
|
||||
// URL → estado inicial (sync)
|
||||
// -----------------------------
|
||||
const initialPanelState = useMemo(() => {
|
||||
const customerId = searchParams.get("customerId");
|
||||
const panelMode = searchParams.get("panel") as RightPanelMode | null;
|
||||
|
||||
if (!customerId) {
|
||||
return {
|
||||
customerId: "",
|
||||
mode: "view" as RightPanelMode,
|
||||
open: false,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
customerId,
|
||||
mode: panelMode ?? "view",
|
||||
open: true,
|
||||
};
|
||||
}, [searchParams]);
|
||||
|
||||
// -----------------------------
|
||||
// Controller con estado inicial
|
||||
// -----------------------------
|
||||
const panelCtrl = useCustomerSummaryPanelController({
|
||||
initialCustomerId: customerId,
|
||||
initialMode: panelMode,
|
||||
initialOpen: customerId !== "",
|
||||
initialCustomerId: initialPanelState.customerId,
|
||||
initialMode: initialPanelState.mode,
|
||||
initialOpen: initialPanelState.open,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@ -25,6 +25,12 @@ export const useListCustomersController = () => {
|
||||
|
||||
const setSearchValue = (value: string) => {
|
||||
setSearch(value.trim().replace(/\s+/g, " "));
|
||||
setPageIndex(0);
|
||||
};
|
||||
|
||||
const setPageSizeValue = (value: number) => {
|
||||
setPageSize(value);
|
||||
setPageIndex(0);
|
||||
};
|
||||
|
||||
return {
|
||||
@ -40,7 +46,7 @@ export const useListCustomersController = () => {
|
||||
pageIndex,
|
||||
pageSize,
|
||||
setPageIndex,
|
||||
setPageSize,
|
||||
setPageSize: setPageSizeValue,
|
||||
|
||||
search,
|
||||
setSearchValue,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user