Skip to content

Commit

Permalink
Added Id count for students
Browse files Browse the repository at this point in the history
  • Loading branch information
ukataria committed Aug 4, 2024
1 parent 140f50f commit cfe89f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/app/create-account/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { Timestamp } from "firebase/firestore";
import { User, Gender } from "@/types/user-types";
import { signUpUser } from "@/lib/firebase/authentication/emailPasswordAuthentication";
import { useRouter } from "next/navigation";
import { getDoc, doc, setDoc } from "firebase/firestore";
import { db } from "@/lib/firebase/firebaseConfig";

export default function CreateAccountPage() {
const [dims, setDims] = useState<Dims>({ width: 0, height: 0 });
Expand Down Expand Up @@ -172,6 +174,7 @@ export default function CreateAccountPage() {
school: string;
grad: string;
yearsInSwaliga: string;
swaligaID: number;
raceEthnicity: RaceEthnicity;
emergencyContacts: {
name: string;
Expand Down Expand Up @@ -203,6 +206,7 @@ export default function CreateAccountPage() {
school: "",
grad: "",
yearsInSwaliga: "",
swaligaID: 0,
raceEthnicity: {
blackOrAfricanAmerican: false,
indigenous: false,
Expand Down Expand Up @@ -264,6 +268,14 @@ export default function CreateAccountPage() {
console.log("Submitting:", accountInfo);
try {
console.log("Entered the try block");

// Gets current SwaligaID
const swaligaIDDoc = await getDoc(doc(db, 'metadata', 'nextUserId'));
let currentSwaligaID = swaligaIDDoc.exists() ? swaligaIDDoc.data().nextUserId : 0;

// Increments it
const newSwaligaID = currentSwaligaID + 1;

const user: User = {
isAdmin: false,
firstName: accountInfo.firstName,
Expand Down Expand Up @@ -296,6 +308,7 @@ export default function CreateAccountPage() {
school: accountInfo.school,
gradYear: parseInt(accountInfo.grad),
yearsWithSwaliga: parseInt(accountInfo.yearsInSwaliga),
swaligaID: newSwaligaID,
ethnicity: new Set(Object.keys(accountInfo.raceEthnicity).filter(key => (accountInfo.raceEthnicity as any)[key] === true)),
assignedSurveys: [],
completedResponses: [],
Expand All @@ -312,6 +325,9 @@ export default function CreateAccountPage() {
console.log("Response:", data);
if (response.ok) {
console.log("Account created successfully:", data);

await setDoc(doc(db, 'metadata', 'nextUserId'), { nextUserId: newSwaligaID });

const authResponse = await signUpUser(accountInfo.email, accountInfo.password);
if (authResponse.success) {
router.push("/student-dashboard");
Expand Down Expand Up @@ -873,7 +889,7 @@ export default function CreateAccountPage() {
</div>
</div>

{/*School field */}
{/* School field */}
<div className={styles.formGroupRow}>
<div className={styles.formGroup}>
<label>
Expand Down Expand Up @@ -925,7 +941,7 @@ export default function CreateAccountPage() {
</div>
</div>

{/* Year you graduate field */}
{/* Years in Swaliga field */}
<div className={styles.formGroupRow}>
<div className={styles.formGroup}>
<label style={{ color: yearsInSwaligaError ? "red" : "inherit" }}>
Expand Down Expand Up @@ -959,7 +975,7 @@ export default function CreateAccountPage() {
</div>
</div>

{/* Ethinicity field */}
{/* Ethnicity field */}
<div className={styles.formGroupRow}>
<div className={styles.formGroup}>
<label>
Expand Down
1 change: 1 addition & 0 deletions src/types/user-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface User {
}[];

id: string;
swaligaID: number;

address: Address;
school: string;
Expand Down

0 comments on commit cfe89f6

Please sign in to comment.