fix(admin/stops): pass admin user_id, not stop.id, as callerUid
StopDetailModal was hardcoding callerUid={stop.id} when rendering
StopProductAssignment, so assign_product_to_stop received the stop's
own UUID as p_caller_uid. The RPC's admin_users.user_id lookup
returned no row, so every assign attempt failed with
'Not recognized as admin'.
The admin's user_id is already known inside the getStopDetails
server action (it gates on getAdminUser()), so surface it on the
response and read it in the modal. The sibling /admin/stops/[id]
page already uses the same source (adminUser.user_id) — this brings
the modal in line with it.
This commit is contained in:
@@ -32,6 +32,8 @@ export type StopDetailsResult =
|
|||||||
allProducts: { id: string; name: string; type: string; price: number }[];
|
allProducts: { id: string; name: string; type: string; price: number }[];
|
||||||
assignedProducts: AssignedProduct[];
|
assignedProducts: AssignedProduct[];
|
||||||
brands: { id: string; name: string; slug: string }[];
|
brands: { id: string; name: string; slug: string }[];
|
||||||
|
/** admin_users.user_id of the caller, forwarded to RPCs that authorise via user_id lookup */
|
||||||
|
callerUid: string;
|
||||||
}
|
}
|
||||||
| { success: false; error: string };
|
| { success: false; error: string };
|
||||||
|
|
||||||
@@ -115,5 +117,6 @@ export async function getStopDetails(stopId: string): Promise<StopDetailsResult>
|
|||||||
allProducts: allProducts ?? [],
|
allProducts: allProducts ?? [],
|
||||||
assignedProducts: (productStops ?? []) as AssignedProduct[],
|
assignedProducts: (productStops ?? []) as AssignedProduct[],
|
||||||
brands: brands ?? [],
|
brands: brands ?? [],
|
||||||
|
callerUid: adminUser.user_id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export default function StopDetailModal({ stopId, onDuplicate, onClose }: Props)
|
|||||||
const [allProducts, setAllProducts] = useState<{ id: string; name: string; type: string; price: number }[]>([]);
|
const [allProducts, setAllProducts] = useState<{ id: string; name: string; type: string; price: number }[]>([]);
|
||||||
const [assignedProducts, setAssignedProducts] = useState<AssignedProduct[]>([]);
|
const [assignedProducts, setAssignedProducts] = useState<AssignedProduct[]>([]);
|
||||||
const [brands, setBrands] = useState<{ id: string; name: string; slug: string }[]>([]);
|
const [brands, setBrands] = useState<{ id: string; name: string; slug: string }[]>([]);
|
||||||
|
const [callerUid, setCallerUid] = useState<string>("");
|
||||||
const [tab, setTab] = useState<Tab>("details");
|
const [tab, setTab] = useState<Tab>("details");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -49,6 +50,7 @@ export default function StopDetailModal({ stopId, onDuplicate, onClose }: Props)
|
|||||||
setAllProducts(res.allProducts);
|
setAllProducts(res.allProducts);
|
||||||
setAssignedProducts(res.assignedProducts);
|
setAssignedProducts(res.assignedProducts);
|
||||||
setBrands(res.brands);
|
setBrands(res.brands);
|
||||||
|
setCallerUid(res.callerUid);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -68,6 +70,7 @@ export default function StopDetailModal({ stopId, onDuplicate, onClose }: Props)
|
|||||||
setAllProducts(res.allProducts);
|
setAllProducts(res.allProducts);
|
||||||
setAssignedProducts(res.assignedProducts);
|
setAssignedProducts(res.assignedProducts);
|
||||||
setBrands(res.brands);
|
setBrands(res.brands);
|
||||||
|
setCallerUid(res.callerUid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +148,7 @@ export default function StopDetailModal({ stopId, onDuplicate, onClose }: Props)
|
|||||||
stopId={stop.id}
|
stopId={stop.id}
|
||||||
allProducts={allProducts}
|
allProducts={allProducts}
|
||||||
assignedProducts={assignedProducts}
|
assignedProducts={assignedProducts}
|
||||||
callerUid={stop.id}
|
callerUid={callerUid}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user