Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Next.js version, add redux and seed population, and create user and role models #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Build a Fullstack Inventory Management Dashboard

[![Tutorial Video](https://img.youtube.com/vi/ddKQ8sZo_v8/0.jpg)](https://www.youtube.com/watch?v=ddKQ8sZo_v8)

Link to related video: https://www.youtube.com/watch?v=ddKQ8sZo_v8

## Tutorial

This repository contains the code corresponding to an in-depth tutorial available on my YouTube channel. It is highly suggested to watch the [tutorial video](https://www.youtube.com/watch?v=ddKQ8sZo_v8) as it includes detailed instructions on how to set up everything, including deploying AWS. This tutorial is designed for both beginners and experts.

Join our [Discord community](https://discord.com/channels/1070200085440376872/1267499814678171698) for discussions about this specific app.

## Tech Stack
## Stack de Tecnologia

- **Next JS**
- **Tailwind**
Expand Down
7 changes: 6 additions & 1 deletion client/package-lock.json

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

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"@reduxjs/toolkit": "^2.2.6",
"axios": "^1.7.2",
"dotenv": "^16.4.5",
"inventory-management": "file:",
"lucide-react": "^0.407.0",
"next": "14.2.4",
"next": "^14.2.4",
"numeral": "^2.0.6",
"react": "^18",
"react-dom": "^18",
Expand Down
7 changes: 7 additions & 0 deletions client/src/app/inventory/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const columns: GridColDef[] = [
type: "number",
},
];
//refatorar
const columnsB : GridColDef[] = [
{ field : "itensId", headName: "ID" , width: 120},
{ field : "selectBoilerplate"},


]

const Inventory = () => {
const { data: products, isError, isLoading } = useGetProductsQuery();
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/products/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ const Products = () => {
className="flex items-center bg-blue-500 hover:bg-blue-700 text-gray-200 font-bold py-2 px-4 rounded"
onClick={() => setIsModalOpen(true)}
>
<PlusCircleIcon className="w-5 h-5 mr-2 !text-gray-200" /> Create
Product
<PlusCircleIcon className="w-5 h-5 mr-2.5 !!text-gray-200" />Criar Produto
</button>
</div>

{/* BODY PRODUCTS LIST */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg-grid-cols-3 gap-10 justify-between">
{isLoading ? (
//Create new loading
<div>Loading...</div>
) : (
products?.map((product) => (
Expand Down
23 changes: 22 additions & 1 deletion client/src/app/redux.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,32 @@ export default function StoreProvider({
}
const persistor = persistStore(storeRef.current);



function logger = (store) =>(next) => {
const crashReporter = storeRef => next => action => {
try {
return next(action)
} catch (err) {
console.error('Encontramos um erro', err)
Raven.captureException(err, {
extra: {
action,
state: store.getState()
}
})
throw err
}
}
}

return (
<Provider store={storeRef.current}>
<PersistGate loading={null} persistor={persistor}>
{children}
</PersistGate>
</Provider>


);
}
}
2 changes: 1 addition & 1 deletion client/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ const config: Config = {
plugins: [createThemes(themes)],
};

export default config;
export default config;
6 changes: 6 additions & 0 deletions package-lock.json

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

7 changes: 6 additions & 1 deletion server/package-lock.json

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

3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"helmet": "^7.1.0",
"morgan": "^1.10.0",
"prisma": "^5.16.2",
"rimraf": "^6.0.1"
"rimraf": "^6.0.1",
"server": "file:"
},
"devDependencies": {
"@types/cors": "^2.8.17",
Expand Down
2 changes: 2 additions & 0 deletions server/prisma/migrations/20240711174419_init/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ CREATE TABLE "SalesSummary" (
"totalValue" DOUBLE PRECISION NOT NULL,
"changePercentage" DOUBLE PRECISION,
"date" TIMESTAMP(3) NOT NULL,
"period" STATUS NOT NULL,
"CHANGE" DOUBLE PRECISION,

CONSTRAINT "SalesSummary_pkey" PRIMARY KEY ("salesSummaryId")
);
Expand Down
24 changes: 19 additions & 5 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
Expand All @@ -13,10 +8,18 @@ datasource db {
url = env("DATABASE_URL")
}

enum Role {
ADMIN
SELLER
MANAGER
DEVELOPER
}

model Users {
userId String @id
name String
email String
role Role?
}

model Products {
Expand All @@ -27,6 +30,15 @@ model Products {
stockQuantity Int
Sales Sales[]
Purchases Purchases[]

Categories Categories[]
}
// This is your Prisma schema file. With a data model like this.

model Categories {
categoryId String @id
name String
Products Products[]
}

model Sales {
Expand Down Expand Up @@ -54,6 +66,8 @@ model Expenses {
category String
amount Float
timestamp DateTime
//
product Products @relation(fields : [category], references: [name])
}

model SalesSummary {
Expand Down
11 changes: 9 additions & 2 deletions server/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ async function main() {
data,
});
}
// Editando os dados
while (const data of jsonData =/= model) {
await model.edit({
data,
head,
})
}

console.log(`Seeded ${modelName} with data from ${fileName}`);
console.log(`Populando ${modelName} com arquivos do ${fileName}`);
}
}

Expand All @@ -66,4 +73,4 @@ main()
})
.finally(async () => {
await prisma.$disconnect();
});
});
2 changes: 2 additions & 0 deletions server/src/controllers/productController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const getProducts = async (
res.json(products);
} catch (error) {
res.status(500).json({ message: "Error retrieving products" });
res.status(400).json({message: "Error for find products"})
}
};

Expand All @@ -38,6 +39,7 @@ export const createProduct = async (
},
});
res.status(201).json(product);
res.status(202).json(product);
} catch (error) {
res.status(500).json({ message: "Error creating product" });
}
Expand Down
23 changes: 23 additions & 0 deletions server/src/routes/useDeleteRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useMutation, useQueryClient } from "@tanstack/react-query"

import { taskMutationKeys } from "../../keys/mutations"
import { taskQueryKeys } from "../../keys/queries"
import { api } from "../../lib/axios"

//Create new Delete Route

export const useDeleteTask = (taskId) => {
const queryClient = useQueryClient()
return useMutation({
mutationKey: taskMutationKeys.delete(),
mutationFn: async () => {
const { data: deletedTask } = await api.delete(`/tasks/${taskId}`)
return deletedTask
},
onSuccess: () => {
queryClient.setQueryData(taskQueryKeys.getAll(), (oldTasks) => {
return oldTasks.filter((task) => task.id !== taskId)
})
},
})
}