@@ -23,7 +23,6 @@ export function ProductionListConfigManager({
|
||||
setColumns,
|
||||
setState,
|
||||
onSave,
|
||||
defaultView,
|
||||
hasUnsavedChanges,
|
||||
setHasUnsavedChanges
|
||||
}) {
|
||||
@@ -34,6 +33,7 @@ export function ProductionListConfigManager({
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isAddingNewProfile, setIsAddingNewProfile] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const [activeView, setActiveView] = useState(() => {
|
||||
const assoc = bodyshop.associations.find((a) => a.useremail === currentUser.email);
|
||||
return assoc && assoc.default_prod_list_view;
|
||||
@@ -257,7 +257,29 @@ export function ProductionListConfigManager({
|
||||
} else {
|
||||
await updateActiveProdView(null);
|
||||
setColumns([]);
|
||||
setState(defaultState); // Reset to default state if no configs are left
|
||||
setState(defaultState);
|
||||
}
|
||||
} else {
|
||||
// Revert back to the active view and load its columns and state
|
||||
const activeConfig = bodyshop.production_config.find((pc) => pc.name === activeView);
|
||||
if (activeConfig) {
|
||||
await updateActiveProdView(activeView);
|
||||
setColumns(
|
||||
activeConfig.columns.columnKeys.map((k) => {
|
||||
return {
|
||||
...ProductionListColumns({
|
||||
technician,
|
||||
state: ensureDefaultState(state),
|
||||
refetch,
|
||||
data: data,
|
||||
activeStatuses: bodyshop.md_ro_statuses.active_statuses,
|
||||
treatments: { Enhanced_Payroll }
|
||||
}).find((e) => e.key === k.key),
|
||||
width: k.width
|
||||
};
|
||||
})
|
||||
);
|
||||
setState(ensureDefaultState(activeConfig.columns.tableState));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -311,7 +333,7 @@ export function ProductionListConfigManager({
|
||||
|
||||
useEffect(() => {
|
||||
const validateAndSetDefaultView = () => {
|
||||
const configExists = bodyshop.production_config.some((pc) => pc.name === defaultView);
|
||||
const configExists = bodyshop.production_config.some((pc) => pc.name === activeView);
|
||||
|
||||
if (!configExists) {
|
||||
// If the default view doesn't exist, revert to the main profile
|
||||
@@ -344,7 +366,7 @@ export function ProductionListConfigManager({
|
||||
}
|
||||
} else {
|
||||
// If the default view exists, set it as active
|
||||
setActiveView(defaultView);
|
||||
setActiveView(activeView);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -356,7 +378,7 @@ export function ProductionListConfigManager({
|
||||
validateAndSetDefaultView();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [defaultView, bodyshop.production_config]);
|
||||
}, [activeView, bodyshop.production_config]);
|
||||
|
||||
const popMenu = (
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user