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