Skip to content

Commit f5e341f

Browse files
committed
add client Home Page
1 parent 60c53f2 commit f5e341f

18 files changed

+764
-68
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@smastrom/react-rating": "^1.5.0",
1717
"@tanstack/react-query": "^5.40.1",
1818
"axios": "^1.7.2",
19+
"date-fns": "^3.6.0",
1920
"firebase": "^10.12.2",
2021
"react": "^18.2.0",
2122
"react-awesome-reveal": "^4.2.11",

src/LayOut/DashBoard.jsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ const DashBoard = () => {
1111
const {logOut} = useAuth()
1212
const [Role] = useAdmin()
1313
const isAdmin = Role?.role;
14+
if (!isAdmin) {
15+
return <div className="flex justify-center items-center">
16+
<span className="loading loading-bars loading-lg"></span>
17+
</div>
18+
}
19+
1420
return (
1521
<div className="container">
1622
<div>
@@ -33,17 +39,17 @@ const DashBoard = () => {
3339
{isAdmin === 'freelancer' && (
3440
<>
3541
<li><Link className="md:text-lg font-semibold"><FaHome className="text-orange-400 text-xl"/>Home</Link></li>
36-
<li><Link className="md:text-lg font-semibold"><FaTasks className="text-orange-400 text-xl"/>Task List</Link></li>
37-
<li><Link className="md:text-lg font-semibold"><GiClockwork className="text-orange-400 text-xl"/>My Submissions</Link></li>
42+
<li><Link to='/dashboard/taskList' className="md:text-lg font-semibold"><FaTasks className="text-orange-400 text-xl"/>Task List</Link></li>
43+
<li><Link to='/dashboard/mySubmission' className="md:text-lg font-semibold"><GiClockwork className="text-orange-400 text-xl"/>My Submissions</Link></li>
3844
</>
3945
)}
4046

4147
{isAdmin === 'client' && (
4248
<>
43-
<li><Link className="md:text-lg font-semibold"><FaHome className="text-orange-400 text-xl"/>Home</Link></li>
49+
<li><Link to='/dashboard/clientHome' className="md:text-lg font-semibold"><FaHome className="text-orange-400 text-xl"/>Home</Link></li>
4450
<li><Link to='/dashboard/addTask' className="md:text-lg font-semibold"><FaTasks className="text-orange-400 text-xl"/>Add New Task</Link></li>
4551
<li><Link to='/dashboard/myTask' className="md:text-lg font-semibold"><GiClockwork className="text-orange-400 text-xl"/>My Task</Link></li>
46-
<li><Link className="md:text-lg font-semibold"><RiShoppingCartFill className="text-orange-400 text-xl"/>Purchase Coin</Link></li>
52+
<li><Link to='/dashboard/buyCoin' className="md:text-lg font-semibold"><RiShoppingCartFill className="text-orange-400 text-xl"/>Purchase Coin</Link></li>
4753
<li><Link className="md:text-lg font-semibold"><FaHistory className="text-orange-400 text-xl"/>Payment History</Link></li>
4854
</>
4955
)}

src/Pages/DashBoard/Add Task/AddTask.jsx

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import useAxiosPublic from "../../../Hooks/useAxiosPublic";
44
import useAuth from "../../../Hooks/useAuth";
55
import useAxiosSecure from "../../../Hooks/useAxiosSecure";
66
import Swal from "sweetalert2";
7+
import useAdmin from "../../../Hooks/useAdmin";
78

89
const image_hosting_key = import.meta.env.VITE_IMAGE_HOSTING_KEY;
910
const image_hosting_api = `https://api.imgbb.com/1/upload?key=${image_hosting_key}`;
1011
const AddTask = () => {
1112
const {user} = useAuth()
13+
const [isAdmin,refetch] = useAdmin()
14+
const adminCoin = isAdmin?.coins;
1215
const axiosPublic = useAxiosPublic()
1316
const axiosSecure = useAxiosSecure()
1417
const {
@@ -26,29 +29,50 @@ const AddTask = () => {
2629
headers:{'content-type' : 'multipart/form-data'}
2730
})
2831
const task_image_url = res.data.data.display_url;
32+
const totalPay = data.quantity * data.money;
33+
const currentCoin = adminCoin - totalPay;
34+
const updateInfo={currentCoin}
2935
const taskInfo = {
3036
task_title:data.title,
3137
task_detail:data.details,
3238
task_quantity:data.quantity,
33-
payable_amount:data.money,
39+
per_task_pay:data.money,
40+
payable_amount:totalPay,
3441
completion_date:data.date,
3542
submission_info:data.submission,
3643
task_image_url,
3744
creator_name,
3845
creator_email
3946
}
40-
const taskRes = await axiosSecure.post('/task',taskInfo)
41-
console.log(taskRes.data);
42-
if (taskRes.data.insertedId) {
43-
reset()
47+
if (totalPay < adminCoin || totalPay === adminCoin ) {
48+
49+
const res = await axiosSecure.patch(`/user/${isAdmin?.email}`,updateInfo)
50+
if (res.data.modifiedCount > 0) {
51+
const taskRes = await axiosSecure.post('/task',taskInfo)
52+
console.log(taskRes.data);
53+
if (taskRes.data.insertedId) {
54+
reset()
55+
Swal.fire({
56+
position: "center",
57+
icon: "success",
58+
title: "Successfuly added task",
59+
showConfirmButton: false,
60+
timer: 1500
61+
});
62+
}
63+
refetch()
64+
}
65+
66+
}
67+
else{
4468
Swal.fire({
45-
position: "center",
46-
icon: "success",
47-
title: "Successfuly added task",
48-
showConfirmButton: false,
49-
timer: 1500
69+
icon: "error",
70+
title: "Not enough coins to add the task",
71+
text: "Please Purchase Coin From below link",
72+
footer: '<Link to="">Purchase Coin</Link>'
5073
});
5174
}
75+
5276

5377
};
5478
return (

src/Pages/DashBoard/Add Task/My Task/MyTask.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import useAxiosSecure from "../../../../Hooks/useAxiosSecure";
44
import { MdDeleteForever, MdEditSquare } from "react-icons/md";
55
import Swal from "sweetalert2";
66
import { Link } from "react-router-dom";
7+
import { RiMoneyEuroCircleLine } from "react-icons/ri";
78

89

910

@@ -61,7 +62,7 @@ const MyTask = () => {
6162

6263
return <tr key={task._id}>
6364
<th>
64-
{index}
65+
{index + 1}
6566
</th>
6667
<td>
6768
<div className="flex items-center gap-3">
@@ -80,7 +81,7 @@ const MyTask = () => {
8081
<td>{task.task_quantity
8182
}</td>
8283
<td>{task.payable_amount
83-
}$</td>
84+
}<RiMoneyEuroCircleLine className="inline-block text-xl text-orange-400 pb-[1px]"/></td>
8485
<th>
8586
<Link to={`/dashboard/myTask/${task._id}`}>
8687
<MdEditSquare className="text-2xl text-green-500"/>

src/Pages/DashBoard/Add Task/My Task/TaskDetails.jsx

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,118 @@
11
import { useLoaderData } from "react-router-dom";
2+
import SectionTitle from "../../../../Component/SectionTitle";
3+
import Swal from "sweetalert2";
4+
import useAxiosSecure from "../../../../Hooks/useAxiosSecure";
5+
import { useForm } from "react-hook-form";
6+
27

38
const TaskDetails = () => {
49
const task = useLoaderData()
5-
console.log(task);
10+
const axiosSecure = useAxiosSecure()
11+
const {
12+
register,
13+
handleSubmit,
14+
formState: { errors },
15+
} = useForm();
16+
const onSubmit = async (data) => {
17+
const totalPay = data.quantity * data.money;
18+
const taskInfo = {
19+
task_title:data.title,
20+
task_detail:data.details,
21+
task_quantity:data.quantity,
22+
per_task_pay:data.money,
23+
payable_amount:totalPay,
24+
completion_date:data.date,
25+
submission_info:data.submission,
26+
}
27+
console.log(taskInfo);
28+
const res = await axiosSecure.patch(`/task/${task._id}`,taskInfo)
29+
console.log(res.data);
30+
if (res.data.modifiedCount > 0) {
31+
Swal.fire({
32+
position: "center",
33+
icon: "success",
34+
title: "Successfuly update task",
35+
showConfirmButton: false,
36+
timer: 1500
37+
});
38+
}
39+
40+
};
641
return (
7-
<div>
8-
{task.task_title}
42+
<div className="">
43+
<SectionTitle
44+
subHeading={"Build Project"}
45+
heading={"update task"}
46+
></SectionTitle>
47+
<div className="p-4">
48+
<form onSubmit={handleSubmit(onSubmit)}>
49+
<div>
50+
<div className="grid md:grid-cols-2 gap-4 grid-cols-1">
51+
<div className="form-control w-full">
52+
<label className="label">
53+
<span className="label-text font-semibold">Task Title</span>
54+
</label>
55+
<input type="text" placeholder="Enter Task Title" defaultValue={task?.task_title}
56+
name="tilte" {...register("title", { required: true })}
57+
className="input input-bordered" />
58+
{errors.title && <span className='text-red-500 mt-2'>This field is required</span>}
59+
</div>
60+
61+
62+
63+
<div className="form-control w-full">
64+
<label className="label">
65+
<span className="label-text font-semibold">Task Quantity</span>
66+
</label>
67+
<input type="number" placeholder="Enter Task Quantity" defaultValue={task?.task_quantity}
68+
name="quantity" {...register("quantity", { required: true })}
69+
className="input input-bordered" />
70+
{errors.quantity && <span className='text-red-500 mt-2'>This field is required</span>}
71+
</div>
72+
<div className="form-control w-full">
73+
<label className="label">
74+
<span className="label-text font-semibold">Amount of Per Task($)</span>
75+
</label>
76+
<input type="number" placeholder="Enter Amount" defaultValue={task?.per_task_pay}
77+
name="money" {...register("money", { required: true })}
78+
className="input input-bordered" />
79+
{errors.money && <span className='text-red-500 mt-2'>This field is required</span>}
80+
</div>
81+
<div className="form-control w-full">
82+
<label className="label">
83+
<span className="label-text font-semibold">Completion Date</span>
84+
</label>
85+
<input type="date" placeholder="Enter DateLine" defaultValue={task?.completion_date}
86+
name="dat" {...register("date", { required: true })}
87+
className="input input-bordered" />
88+
{errors.date && <span className='text-red-500 mt-2'>This field is required</span>}
89+
</div>
90+
<div className="form-control w-full">
91+
<label className="label">
92+
<span className="label-text font-semibold">Task Details</span>
93+
</label>
94+
<textarea className='textarea textarea-bordered w-full' rows="4" type="text" defaultValue={task?.task_detail} placeholder="Enter Task Details"
95+
name="details" {...register("details", { required: true })}
96+
/>
97+
{errors.details && <span className='text-red-500 mt-2'>This field is required</span>}
98+
</div>
99+
<div className="form-control w-full">
100+
<label className="label">
101+
<span className="label-text font-semibold">Submission Info</span>
102+
</label>
103+
<textarea className='textarea textarea-bordered w-full' rows="4" defaultValue={task?.submission_info} type="text" placeholder="Enter Submission Info"
104+
name="submission" {...register("submission", { required: true })}
105+
/>
106+
{errors.submission && <span className='text-red-500 mt-2'>This field is required</span>}
107+
</div>
9108
</div>
109+
<div className="w-full mt-4">
110+
<button className="btn btn-primary w-full " type="submit">Update Task</button>
111+
</div>
112+
</div>
113+
</form>
114+
</div>
115+
</div>
10116
);
11117
};
12118

0 commit comments

Comments
 (0)