Skip to content

Commit 0e9514a

Browse files
committed
update create
1 parent 24c15c4 commit 0e9514a

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

app/recipes/create/page.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client"
2-
import { CheckIcon } from "@heroicons/react/24/solid";
2+
import { CheckIcon, InboxArrowDownIcon } from "@heroicons/react/24/solid";
33
import { ChangeEvent, FormEvent, useState } from "react";
44
import Button from "../../../components/ui/Button";
55
import { IRecipCreate, Ingredients } from "../../../models/recipe";
@@ -19,7 +19,8 @@ export default function CreateRecipe() {
1919
const [singleIngredient, setSingleIngredient] = useState("");
2020
const [ingredients, setIngredients] = useState<Ingredients[]>([]);
2121
const [selectedPhoto, setSelectedPhoto] = useState<File | null>(null);
22-
const [loading, setLoading] = useState(true)
22+
const [loading, setLoading] = useState(false)
23+
const [apiMessage, setApiMessage] = useState("")
2324

2425
// تابع handlePhotoChange برای مدیریت تغییرات در ورودی عکس
2526
const handlePhotoChange = (event: ChangeEvent<HTMLInputElement>) => {
@@ -40,7 +41,7 @@ export default function CreateRecipe() {
4041
// موارد بعد از شاخص درج:
4142
...ingredients.slice(insertAt),
4243
];
43-
console.log("next", nextIngredients);
44+
// console.log("next", nextIngredients);
4445

4546
setIngredients(nextIngredients);
4647
setSingleIngredient("");
@@ -64,13 +65,23 @@ export default function CreateRecipe() {
6465
};
6566
try {
6667
const saveRecip = await fetch("/api/recipes", options);
67-
setLoading(false)
6868
if (saveRecip.status === 200) {
69-
console.log(saveRecip);
69+
setLoading(false)
70+
console.log(saveRecip.json());
71+
setApiMessage("رسپی ساخته شد!")
72+
73+
setTimeout(() => {
74+
setApiMessage("")
75+
}, 4000);
7076
}
7177
} catch (error) {
7278
setLoading(false)
7379
console.log(error);
80+
setApiMessage("مشکلی در ساخت رسپی به وجود آمد")
81+
82+
setTimeout(() => {
83+
setApiMessage("")
84+
}, 4000);
7485
}
7586
}
7687
};
@@ -183,11 +194,22 @@ export default function CreateRecipe() {
183194
<Button
184195
type="submit"
185196
className="w-96 py-3 px-4 inline-flex justify-center items-center gap-2 rounded-md border border-transparent font-semibold bg-cyan-700 text-white hover:bg-cyan-500 focus:outline-none focus:ring-2 focus:ring-cyan-500 focus:ring-offset-2 transition-all text-sm"
197+
disabled={loading}
186198
>
199+
{
200+
loading &&
201+
<InboxArrowDownIcon width={20} />
202+
}
187203
<span>ساخت رسپی</span>
188204
</Button>
189205
</div>
190206
</form>
207+
{apiMessage &&
208+
<div className="flex w-96 mx-auto m-4 p-4 rounded bg-slate-50">
209+
<p className=" text-gray-500 px-2">پیام سیستم:</p>
210+
<p className=" text-green-600 font-bold">{apiMessage}</p>
211+
</div>
212+
}
191213
</section>
192214
</div>
193215
</div>

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ services:
99
NEXT_PUBLIC_ENV_VARIABLE: ${NEXT_PUBLIC_ENV_VARIABLE}
1010
restart: always
1111
volumes:
12-
- ./:/app
1312
- /app/node_modules
1413
- /app/.next
1514
ports:
1615
- "${PORT}:${PORT}"
1716
environment:
18-
DB_LOCAL_URL: mongodb://mongo:27017/denizpazs
17+
DB_LOCAL_URL: mongodb://mongo:27017/denizpaz
1918
depends_on:
2019
- mongo
2120
networks:

lib/mongodb.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import mongoose, { connect, connection } from 'mongoose'
22

3-
// const { MONGODB = 'mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false' } = process.env;
4-
// const DATABASE = "mongodb+srv://ghafari5000:[email protected]/?retryWrites=true&w=majority"
5-
const DATABASE = "mongodb://mongo:27017/denizpazs"
3+
const DATABASE = "mongodb://mongo:27017/denizpaz"
64
const options: any = {
75
useUnifiedTopology: true,
86
useNewUrlParser: true
@@ -12,7 +10,7 @@ const options: any = {
1210
export const connectToDatabase = async () => {
1311
if (!connection.readyState) {
1412
// console.log('Connecting to ', DATABASE)
15-
await mongoose.connect(DATABASE, options)
13+
await mongoose.connect(DATABASE || "mongodb://mongo:27017/denizpaz", options)
1614
.then((c) => {
1715
console.log("Mongo Connected: ")
1816
})

0 commit comments

Comments
 (0)