Skip to content

Commit 2fd6b92

Browse files
authored
Merge branch 'main' into feature/vitest
2 parents 8d37ae3 + ee29610 commit 2fd6b92

115 files changed

Lines changed: 15867 additions & 11219 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,23 @@ yarn-error.log*
3636
# typescript
3737
*.tsbuildinfo
3838
next-env.d.ts
39+
40+
# Database backups
41+
/backups/
42+
*.sql
43+
*.dump
44+
*.backup
45+
46+
# Logs
47+
*.log
48+
logs/
49+
50+
# IDE
51+
.vscode/
52+
.idea/
53+
*.swp
54+
*.swo
55+
56+
# OS
57+
Thumbs.db
58+
.DS_Store

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,18 @@ We have applied this method by examining the code after each new added functiona
124124
</ol>
125125

126126
```
127-
DATABASE_URL="mysql://username:password@localhost:3306/singitronic_nextjs"
127+
NEXT_PUBLIC_API_BASE_URL=http://localhost:3001
128+
NODE_ENV=development
129+
DATABASE_URL="mysql://username:password@localhost:3306/singitronic_nextjs?sslmode=disabled"
128130
NEXTAUTH_SECRET=12D16C923BA17672F89B18C1DB22A
129131
NEXTAUTH_URL=http://localhost:3000
130132
```
131133

132134
<p>7. After you do it, you need to create another .env file in the server folder and put the same DATABASE_URL you used in the previous .env file:</p>
133135

134136
```
135-
DATABASE_URL="mysql://username:password@localhost:3306/singitronic_nextjs"
137+
NODE_ENV=development
138+
DATABASE_URL="mysql://username:password@localhost:3306/singitronic_nextjs?sslmode=disabled"
136139
```
137140

138141
<p>8. Now you need to open your terminal of choice in the root folder of the project and write:</p>

app/(dashboard)/admin/categories/[id]/page.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
"use client";
22
import { DashboardSidebar } from "@/components";
33
import { useRouter } from "next/navigation";
4-
import React, { useEffect, useState } from "react";
4+
import React, { useEffect, useState, use } from "react";
55
import toast from "react-hot-toast";
66
import { formatCategoryName } from "../../../../../utils/categoryFormating";
77
import { convertCategoryNameToURLFriendly } from "../../../../../utils/categoryFormating";
8+
import apiClient from "@/lib/api";
89

910
interface DashboardSingleCategoryProps {
10-
params: { id: number };
11+
params: Promise<{ id: string }>;
1112
}
1213

1314
const DashboardSingleCategory = ({
14-
params: { id },
15+
params,
1516
}: DashboardSingleCategoryProps) => {
17+
const resolvedParams = use(params);
18+
const id = resolvedParams.id;
19+
1620
const [categoryInput, setCategoryInput] = useState<{ name: string }>({
1721
name: "",
1822
});
@@ -23,7 +27,7 @@ const DashboardSingleCategory = ({
2327
method: "DELETE",
2428
};
2529
// sending API request for deleting a category
26-
fetch(`http://localhost:3001/api/categories/${id}`, requestOptions)
30+
apiClient.delete(`/api/categories/${id}`, requestOptions)
2731
.then((response) => {
2832
if (response.status === 204) {
2933
toast.success("Category deleted successfully");
@@ -47,7 +51,7 @@ const DashboardSingleCategory = ({
4751
}),
4852
};
4953
// sending API request for updating a category
50-
fetch(`http://localhost:3001/api/categories/${id}`, requestOptions)
54+
apiClient.put(`/api/categories/${id}`, requestOptions)
5155
.then((response) => {
5256
if (response.status === 200) {
5357
return response.json();
@@ -67,7 +71,7 @@ const DashboardSingleCategory = ({
6771

6872
useEffect(() => {
6973
// sending API request for getting single categroy
70-
fetch(`http://localhost:3001/api/categories/${id}`)
74+
apiClient.get(`/api/categories/${id}`)
7175
.then((res) => {
7276
return res.json();
7377
})

app/(dashboard)/admin/categories/new/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DashboardSidebar } from "@/components";
33
import React, { useState } from "react";
44
import toast from "react-hot-toast";
55
import { convertCategoryNameToURLFriendly } from "../../../../../utils/categoryFormating";
6+
import apiClient from "@/lib/api";
67

78
const DashboardNewCategoryPage = () => {
89
const [categoryInput, setCategoryInput] = useState({
@@ -19,7 +20,7 @@ const DashboardNewCategoryPage = () => {
1920
}),
2021
};
2122
// sending API request for creating new cateogry
22-
fetch(`http://localhost:3001/api/categories`, requestOptions)
23+
apiClient.post(`/api/categories`, requestOptions)
2324
.then((response) => {
2425
if (response.status === 201) {
2526
return response.json();

app/(dashboard)/admin/categories/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { nanoid } from "nanoid";
44
import Link from "next/link";
55
import React, { useEffect, useState } from "react";
66
import { formatCategoryName } from "../../../../utils/categoryFormating";
7+
import apiClient from "@/lib/api";
78

89
const DashboardCategory = () => {
910
const [categories, setCategories] = useState<Category[]>([]);
1011

1112
// getting all categories to be displayed on the all categories page
1213
useEffect(() => {
13-
fetch("http://localhost:3001/api/categories")
14+
apiClient.get("/api/categories")
1415
.then((res) => {
1516
return res.json();
1617
})

0 commit comments

Comments
 (0)