Skip to content

Commit 81414a8

Browse files
authored
Merge pull request #71 from Coding-Club-IITG/shreya
delete year
2 parents 3481011 + b67bc69 commit 81414a8

File tree

11 files changed

+522
-26
lines changed

11 files changed

+522
-26
lines changed

client/src/api/Year.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import axios from "axios";
2+
import serverRoot from "./server";
3+
import { Children } from "react";
4+
5+
// Create axios instance with baseURL and withCredentials
6+
const API = axios.create({
7+
baseURL: `${serverRoot}/api`,
8+
withCredentials: true,
9+
});
10+
11+
// Attach token to every request if available (from localStorage)
12+
API.interceptors.request.use((req) => {
13+
const user = JSON.parse(localStorage.getItem("profile"));
14+
if (user) req.headers.Authorization = `Bearer ${user.token}`;
15+
return req;
16+
});
17+
18+
export const addYear = async ({ name, course}) => {
19+
const { data } = await API.post("/year", {
20+
name,
21+
course,
22+
childType:"Folder",
23+
Children:[],
24+
});
25+
return data;
26+
};
27+
28+
export const deleteYear = async ({ folder, courseCode}) => {
29+
const { data } = await API.delete("/year/delete", {
30+
data:{folder, courseCode}
31+
});
32+
return data;
33+
};

client/src/screens/browse/components/collapsible/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ const Collapsible = ({ course, color, state }) => {
9696
toast.error("Course data could not be loaded.");
9797
return;
9898
}
99-
99+
dispatch(ChangeCurrentCourse(fetched.children, fetched.code));
100100
const yearIndex = fetched.children.length - 1;
101101
const yearFolder = fetched.children?.[yearIndex];
102102

103103
if (!yearFolder) {
104-
toast.warn("No folders available for this course.");
104+
//toast.warn("No folders available for this course.");
105105
dispatch(ChangeCurrentYearData(yearIndex, []));
106106
dispatch(ChangeFolder(null));
107107
return;
@@ -111,7 +111,7 @@ const Collapsible = ({ course, color, state }) => {
111111

112112
dispatch(ChangeCurrentYearData(yearIndex, yearChildren));
113113
dispatch(ChangeFolder(yearFolder));
114-
dispatch(ChangeCurrentCourse(fetched.children, fetched.code));
114+
115115
setInitial(false);
116116
} catch (error) {
117117
console.error( error);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import React from "react";
2+
import cross from "../browsefolder/cross.svg";
3+
4+
const styles = {
5+
overlay: {
6+
position: "fixed",
7+
top: 0,
8+
left: 0,
9+
right: 0,
10+
bottom: 0,
11+
backgroundColor: "rgba(0, 0, 0, 0.4)",
12+
display: "flex",
13+
alignItems: "center",
14+
justifyContent: "center",
15+
zIndex: 1000,
16+
},
17+
dialog: {
18+
backgroundColor: "#fff",
19+
padding: "25px 30px",
20+
borderRadius: "8px",
21+
maxWidth: "400px",
22+
width: "90%",
23+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.2)",
24+
textAlign: "center",
25+
fontFamily: "sans-serif",
26+
},
27+
28+
iconImage: {
29+
width: "80px",
30+
height: "80px",
31+
margin: "1em",
32+
33+
},
34+
heading: {
35+
fontSize: "2em",
36+
},
37+
message: {
38+
fontSize: "1em",
39+
color: "#374151",
40+
margin: "1em",
41+
},
42+
buttonGroup: {
43+
display: "flex",
44+
justifyContent: "center",
45+
gap: "1em",
46+
},
47+
deleteBtn: {
48+
display: "flex",
49+
alignItems: "center",
50+
backgroundColor: "#ef4444",
51+
color: "#fff",
52+
border: "none",
53+
padding: "10px 18px",
54+
borderRadius: "5px",
55+
cursor: "pointer",
56+
fontWeight: "bold",
57+
fontSize: "1em",
58+
},
59+
cancelBtn: {
60+
backgroundColor: "#9ca3af",
61+
color: "#fff",
62+
border: "none",
63+
padding: "10px 18px",
64+
borderRadius: "5px",
65+
cursor: "pointer",
66+
fontWeight: "bold",
67+
fontSize: "1em",
68+
},
69+
};
70+
71+
72+
const ConfirmDelDialog = ({ isOpen, onConfirm, onCancel }) => {
73+
if (!isOpen) return null;
74+
75+
return (
76+
<div style={styles.overlay}>
77+
<div style={styles.dialog}>
78+
<img src={cross} alt="Delete" style={styles.iconImage} />
79+
<h3 style={styles.heading}>Are you sure?</h3>
80+
<p style={styles.message}>
81+
All the folders and files inside this year will be permanently deleted.
82+
Do you want to permanently delete this year? This action cannot be undone.
83+
</p>
84+
<div style={styles.buttonGroup}>
85+
<button style={styles.cancelBtn} onClick={onCancel}>
86+
Cancel
87+
</button>
88+
<button style={styles.deleteBtn} onClick={onConfirm}>
89+
Delete
90+
</button>
91+
</div>
92+
</div>
93+
</div>
94+
);
95+
};
96+
97+
export { ConfirmDelDialog };
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import React from "react";
2+
import options from "./year-options";
3+
const styles = {
4+
overlay: {
5+
position: "fixed",
6+
top: 0,
7+
left: 0,
8+
right: 0,
9+
bottom: 0,
10+
backgroundColor: "rgba(0, 0, 0, 0.4)",
11+
display: "flex",
12+
alignItems: "center",
13+
justifyContent: "center",
14+
zIndex: 1000,
15+
},
16+
dialog: {
17+
backgroundColor: "#fff",
18+
padding: "25px 30px",
19+
borderRadius: "8px",
20+
maxWidth: "400px",
21+
width: "90%",
22+
boxShadow: "0 4px 20px rgba(0, 0, 0, 0.2)",
23+
textAlign: "center",
24+
fontFamily: "sans-serif",
25+
},
26+
heading: {
27+
fontSize: "2em",
28+
marginBottom: "0.5em",
29+
},
30+
input: {
31+
padding: "10px",
32+
fontSize: "1em",
33+
width: "100%",
34+
marginBottom: "1.5em",
35+
border: "1px solid #ccc",
36+
borderRadius: "5px",
37+
},
38+
selectLabel: {
39+
textAlign: "left",
40+
fontWeight: "500",
41+
marginBottom: "0.3em",
42+
display: "block",
43+
},
44+
select: {
45+
width: "100%",
46+
padding: "10px",
47+
fontSize: "1em",
48+
marginBottom: "1.5em",
49+
border: "1px solid #ccc",
50+
borderRadius: "5px",
51+
},
52+
buttonGroup: {
53+
display: "flex",
54+
justifyContent: "center",
55+
gap: "1em",
56+
},
57+
confirmBtn: {
58+
backgroundColor: "#22c55e",
59+
color: "#fff",
60+
border: "none",
61+
padding: "10px 18px",
62+
borderRadius: "5px",
63+
cursor: "pointer",
64+
fontWeight: "bold",
65+
fontSize: "1em",
66+
},
67+
cancelBtn: {
68+
backgroundColor: "#9ca3af",
69+
color: "#fff",
70+
border: "none",
71+
padding: "10px 18px",
72+
borderRadius: "5px",
73+
cursor: "pointer",
74+
fontWeight: "bold",
75+
fontSize: "1em",
76+
},
77+
};
78+
79+
const ConfirmDialog = ({
80+
show,
81+
// input = false,
82+
// inputValue = "",
83+
// onInputChange = () => {},
84+
yearName = "",
85+
onYearNameChange = () => {},
86+
onCancel,
87+
onConfirm,
88+
confirmText = "Confirm",
89+
cancelText = "Cancel",
90+
}) => {
91+
if (!show) return null;
92+
93+
return (
94+
<div style={styles.overlay}>
95+
<div style={styles.dialog}>
96+
<h2 style={styles.heading}>Enter Year Name</h2>
97+
{/* {input && (
98+
<input
99+
type="text"
100+
placeholder="Year name"
101+
value={inputValue}
102+
onChange={onInputChange}
103+
style={styles.input}
104+
/>
105+
)} */}
106+
<select
107+
value={yearName}
108+
onChange={(e) => onYearNameChange(e.target.value)}
109+
style={styles.select}
110+
>
111+
<option value="" disabled>
112+
Select year
113+
</option>
114+
115+
{options.map((opt, idx) => {
116+
return (
117+
<option
118+
className={"option"}
119+
value={opt}
120+
>
121+
{opt}
122+
</option>
123+
);
124+
})}
125+
126+
</select>
127+
<div style={styles.buttonGroup}>
128+
<button style={styles.cancelBtn} onClick={onCancel}>
129+
{cancelText}
130+
</button>
131+
<button style={styles.confirmBtn} onClick={onConfirm}>
132+
{confirmText}
133+
</button>
134+
</div>
135+
</div>
136+
</div>
137+
);
138+
};
139+
140+
export { ConfirmDialog };

0 commit comments

Comments
 (0)