Skip to content

Commit

Permalink
feat: add delete product
Browse files Browse the repository at this point in the history
  • Loading branch information
nisrinasalm committed Oct 9, 2024
1 parent 5b7a469 commit fcf1191
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
7 changes: 7 additions & 0 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ public function show(string $id) {
return Inertia::render('Product/Show', compact('product'));
}

public function destroy(string $id) {
$product = Product::findOrFail($id);
$product->delete();

return redirect()->route('product.index');
}

}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"vite": "^5.0"
},
"dependencies": {
"@inertiajs/inertia": "^0.11.1",
"clsx": "^2.1.1",
"lucide-react": "^0.451.0",
"tailwind-merge": "^2.5.3"
Expand Down
23 changes: 23 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions resources/js/Layouts/GuestLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import ApplicationLogo from "@/Components/ApplicationLogo";
import { Link } from "@inertiajs/react";
import UnstyledLink from "@/Components/UnstyledLink";
import type { PropsWithChildren } from "react";

export default function Guest({ children }: PropsWithChildren) {
return (
<div className="flex min-h-screen flex-col items-center bg-gray-100 pt-6 sm:justify-center sm:pt-0">
<div>
<Link href="/">
<UnstyledLink href="/">
<ApplicationLogo className="h-20 w-20 fill-current text-gray-500" />
</Link>
</UnstyledLink>
</div>

<div className="mt-6 w-full overflow-hidden bg-white px-6 py-4 shadow-md sm:max-w-md sm:rounded-lg">
Expand Down
15 changes: 13 additions & 2 deletions resources/js/Pages/Product/Show.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import Button from "@/Components/Button";
import ButtonLink from "@/Components/ButtonLink";
import Typography from "@/Components/Typography";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { ProductType } from "@/types/entities/product";
import { Inertia } from "@inertiajs/inertia";
import { Head } from "@inertiajs/react";
import { ArrowLeft } from "lucide-react";

export default function Show({ product }: { product: ProductType }) {
const handleDelete = () => {
if (confirm("Are you sure you want to delete this product?")) {
Inertia.delete(`/product/${product.id}/delete`, {
onSuccess: () => {
alert("Product deleted successfully!");
},
});
}
};
return (
<AuthenticatedLayout>
<Head title="Detail Product" />
Expand Down Expand Up @@ -48,9 +59,9 @@ export default function Show({ product }: { product: ProductType }) {
<ButtonLink href="/" className="flex w-3/5">
Edit Product
</ButtonLink>
<ButtonLink href="/" className="flex w-3/5">
<Button onClick={handleDelete} className="flex w-3/5">
Delete Product
</ButtonLink>
</Button>
</div>
</div>
</AuthenticatedLayout>
Expand Down

0 comments on commit fcf1191

Please sign in to comment.