Skip to content

Commit 887a945

Browse files
authored
Student upload & Recaptcha (#385)
2 parents 0a2104d + 0ed2c24 commit 887a945

6 files changed

Lines changed: 318 additions & 138 deletions

File tree

.env.development

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
NEXT_PUBLIC_BACKEND_URL=https://tpc.princecodes.online
2-
NEXT_PUBLIC_FRONTEND_URL=https://tpc.princecodes.online
3-
NEXTAUTH_URL=https://tpc.princecodes.online/portal/api/auth
4-
NEXT_PUBLIC_RECAPTCHA_SITE_KEY=6Ldqk2crAAAAAArTeCabZFi1yIJwolU-E82cnMmR
1+
NEXT_PUBLIC_BACKEND_URL=https://tpc.jxp.codes
2+
NEXT_PUBLIC_FRONTEND_URL=https://tpc.jxp.codes
3+
NEXTAUTH_URL=https://tpc.jxp.codes/portal/api/auth
4+
NEXT_PUBLIC_RECAPTCHA_SITE_KEY=6Ldd9KYrAAAAAO2UAAHuvK-lSFU3qj6HqXHzf5o1
55
NEXT_PUBLIC_BASE_PATH="/portal"
66
NEXT_PUBLIC_ASSET_PREFIX="/portal"

.github/workflows/docker-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ jobs:
3434
- name: Copy environment file
3535
run: |
3636
if [ "${{ github.ref_name }}" = "main" ]; then
37-
cp .env.production .env
37+
cp .env.production .env.production.local
3838
elif [ "${{ github.ref_name }}" = "develop" ]; then
39-
cp .env.development .env
39+
cp .env.development .env.production.local
4040
else
4141
echo "Unknown branch: ${{ github.ref_name }}"
4242
exit 1

src/app/(routes)/admin/students/page.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ const StudentPage = () => {
8484
},
8585
}));
8686
await addStudents(payload);
87-
toast.success("Students added successfully");
87+
toast.success(
88+
`Successfully imported ${data.length} student${data.length > 1 ? "s" : ""}`,
89+
);
8890
setImportOpen(false);
91+
92+
// Refresh student data
93+
const updatedData = await fetchStudentData();
94+
setStudents(updatedData);
8995
} catch (e) {
9096
toast.error("Failed to add students");
9197
}
@@ -94,7 +100,47 @@ const StudentPage = () => {
94100

95101
const parseStudentRow = (row: any) => {
96102
if (!row.rollNo || !row.name || !row.email) return null;
97-
return row;
103+
104+
// Convert enum fields to uppercase for backend compatibility
105+
const category = row.category?.toUpperCase();
106+
const gender = row.gender?.toUpperCase();
107+
108+
// Validate enum values
109+
const validCategories = [
110+
"GENERAL",
111+
"OBC",
112+
"SC",
113+
"ST",
114+
"EWS",
115+
"GENERAL_PWD",
116+
"OBC_PWD",
117+
"SC_PWD",
118+
"ST_PWD",
119+
"EWS_PWD",
120+
];
121+
const validGenders = ["MALE", "FEMALE", "OTHER"];
122+
123+
if (category && !validCategories.includes(category)) {
124+
console.warn(`Invalid category: ${category} for student ${row.rollNo}`);
125+
return null;
126+
}
127+
128+
if (gender && !validGenders.includes(gender)) {
129+
console.warn(`Invalid gender: ${gender} for student ${row.rollNo}`);
130+
return null;
131+
}
132+
133+
const processedRow = {
134+
rollNo: row.rollNo,
135+
category: category,
136+
gender: gender,
137+
cpi: row.cpi,
138+
name: row.name,
139+
email: row.email,
140+
contact: row.contact,
141+
};
142+
143+
return processedRow;
98144
};
99145

100146
const handleBulkAction = (rows: DTO[]) => {
@@ -175,6 +221,7 @@ const StudentPage = () => {
175221
templateFileName="students_template.csv"
176222
parseRow={parseStudentRow}
177223
entityName="students"
224+
cleanData={true}
178225
/>
179226
<div>
180227
{students.length > 0 && (

0 commit comments

Comments
 (0)