mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
more, more, more
This commit is contained in:
@@ -7,15 +7,19 @@ export const getData = async () => {
|
||||
const data = await db.select().from(brand).orderBy(asc(brand.name));
|
||||
return data;
|
||||
};
|
||||
|
||||
export const addBrand = async ( name: string) => {
|
||||
await db.insert(brand).values({
|
||||
name: name,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteBrand = async (id: number) => {
|
||||
"use server";
|
||||
await db.delete(brand).where(eq(brand.id, id));
|
||||
revalidatePath("/");
|
||||
revalidatePath("/Brands");
|
||||
};
|
||||
|
||||
export const editBrand = async (id: number, name: string) => {
|
||||
await db
|
||||
.update(brand)
|
||||
|
||||
10
src/actions/manufacturerActions.ts
Normal file
10
src/actions/manufacturerActions.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
"use server";
|
||||
import { eq, not , asc} from "drizzle-orm";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { db } from "../db";
|
||||
import { manufacturer } from "@/db/schema/Manufacturer";
|
||||
export const getData = async () => {
|
||||
const data = await db.select().from(manufacturer).orderBy(asc(manufacturer.name));
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Account } from "@/db/schema/Account";
|
||||
import { getData } from "../../actions/accountActions";
|
||||
import Brands from "../../components/Brand/brands";
|
||||
import Brands from "../../components/Brand/BrandsList";
|
||||
|
||||
export default async function AccountsPage() {
|
||||
const data = await getData();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { getData } from "../../actions/brandActions";
|
||||
import Brands from "../../components/Brand/brands";
|
||||
import BrandsList from "../../components/Brand/BrandsList";
|
||||
|
||||
export default async function BrandsPage() {
|
||||
const data = await getData();
|
||||
return (
|
||||
<div className="bg-gray-100 min-h-screen flex flex-col">
|
||||
<Brands brands={data} />
|
||||
<BrandsList brands={data} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,15 +7,18 @@ import { addBrand, deleteBrand, editBrand } from "../../actions/brandActions";
|
||||
interface Props {
|
||||
brands: brandType[];
|
||||
}
|
||||
const Brands: FC<Props> = ({ brands }) => {
|
||||
|
||||
const BrandsList: FC<Props> = ({ brands }) => {
|
||||
// State to manage the list of brand items
|
||||
const [brandItems, setBrandItems] = useState<brandType[]>(brands);
|
||||
|
||||
// Function to create a new brand item
|
||||
const createBrand = (name: string) => {
|
||||
const id = (brandItems.at(-1)?.id || 0) + 1;
|
||||
addBrand(name);
|
||||
setBrandItems((prev) => [...prev, { id: id, name: name }]);
|
||||
};
|
||||
|
||||
// Function to change the text of a brand item
|
||||
const changeBrandName = (id: number, name: string) => {
|
||||
setBrandItems((prev) =>
|
||||
@@ -25,10 +28,11 @@ const Brands: FC<Props> = ({ brands }) => {
|
||||
};
|
||||
|
||||
// Function to delete a brand item
|
||||
const deleteTodoItem = (id: number) => {
|
||||
const deleteBrandItem = (id: number) => {
|
||||
setBrandItems((prev) => prev.filter((brand) => brand.id !== id));
|
||||
deleteBrand(id);
|
||||
};
|
||||
|
||||
// Rendering the brand List component
|
||||
return (
|
||||
<main className="flex mx-auto max-w-xl w-full min-h-screen flex-col items-center p-16">
|
||||
@@ -49,4 +53,4 @@ const Brands: FC<Props> = ({ brands }) => {
|
||||
</main>
|
||||
);
|
||||
};
|
||||
export default Brands;
|
||||
export default BrandsList;
|
||||
@@ -40,7 +40,7 @@ const Brand: FC<Props> = ({
|
||||
deleteBrand(brand.id);
|
||||
}
|
||||
};
|
||||
// Rendering the Todo component
|
||||
// Rendering the Brands component
|
||||
return (
|
||||
<div className="flex items-center gap-2 p-4 border-gray-200 border-solid border rounded-lg">
|
||||
{/* Checkbox for marking the todo as done */}
|
||||
|
||||
9
src/db/schema/ComponentTypes.ts
Normal file
9
src/db/schema/ComponentTypes.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { timestamps } from "./helpers/columns.helpers";
|
||||
|
||||
export const ComponentType = pgTable("component_type", {
|
||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "component_type_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
name: varchar({length: 100}).notNull(),
|
||||
...timestamps
|
||||
})
|
||||
9
src/db/schema/Manufacturer.ts
Normal file
9
src/db/schema/Manufacturer.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { timestamps } from "./helpers/columns.helpers";
|
||||
|
||||
export const manufacturer = pgTable("manufacturer", {
|
||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "manufacturer_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||
name: varchar({length:100}).notNull(),
|
||||
...timestamps
|
||||
})
|
||||
12
src/types/accountType.ts
Normal file
12
src/types/accountType.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export type brandType = {
|
||||
id: number;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
username : string;
|
||||
email: string;
|
||||
password_hash: string;
|
||||
updated_at: Date;
|
||||
created_at: Date;
|
||||
deleted_at: Date;
|
||||
|
||||
};
|
||||
9
src/types/allTypes.ts
Normal file
9
src/types/allTypes.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export type brandType = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type manufacturerType = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
4
src/types/manufacturerType.ts
Normal file
4
src/types/manufacturerType.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export type manufacturerType = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
Reference in New Issue
Block a user