feat(product): 優化編輯後的跳轉邏輯,支援依來源回傳詳情頁或列表

This commit is contained in:
2026-02-05 16:01:29 +08:00
parent 075b9f1c98
commit 1d5bc68444
4 changed files with 15 additions and 4 deletions

View File

@@ -22,6 +22,8 @@ export default function ProductForm({
units,
}: ProductFormProps) {
const isEdit = !!initialData;
const urlParams = new URLSearchParams(window.location.search);
const from = urlParams.get('from');
const { data, setData, post, put, processing, errors } = useForm({
code: initialData?.code || "",
@@ -45,7 +47,7 @@ export default function ProductForm({
e.preventDefault();
if (isEdit) {
put(route("products.update", initialData.id), {
put(route("products.update", { product: initialData.id, from }), {
onSuccess: () => toast.success("商品已更新"),
onError: () => toast.error("更新失敗,請檢查輸入資料"),
});

View File

@@ -14,6 +14,11 @@ interface Props {
}
export default function Edit({ product, categories, units }: Props) {
const urlParams = new URLSearchParams(window.location.search);
const from = urlParams.get('from');
const backUrl = from === 'show' ? route('products.show', product.id) : route('products.index');
const backText = from === 'show' ? "返回商品詳情" : "返回商品列表";
return (
<AuthenticatedLayout
breadcrumbs={getEditBreadcrumbs("products")}
@@ -23,13 +28,13 @@ export default function Edit({ product, categories, units }: Props) {
<div className="container mx-auto p-6 max-w-7xl">
{/* Header */}
<div className="mb-6">
<Link href={route("products.index")}>
<Link href={backUrl}>
<Button
variant="outline"
className="gap-2 button-outlined-primary mb-4"
>
<ArrowLeft className="h-4 w-4" />
{backText}
</Button>
</Link>

View File

@@ -67,7 +67,7 @@ export default function ProductShow({ product }: Props) {
</div>
<div className="flex gap-2">
<Can permission="products.edit">
<Link href={route('products.edit', product.id)}>
<Link href={route('products.edit', { product: product.id, from: 'show' })}>
<Button className="button-filled-primary">
</Button>