Skip to content

Conversation

@CH-JASWANTH-KUMAR
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings January 1, 2026 17:39
@ManasMalla ManasMalla merged commit f30cc3f into dsc-gitam:main Jan 1, 2026
5 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables team members to view their team's problem statement by implementing a dual-fetch and dual-save strategy. Previously, problem statements were only stored in the team leader's profile, making them inaccessible to other team members.

Key Changes:

  • Added logic to fetch problem statements from team documents or fallback to the leader's profile when team members load their profiles
  • Modified the save operation to persist problem statements to both the user's profile and the team document for shared visibility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +159 to +173
// Save to user profile (legacy support)
await updateDoc(doc(db, "registrations", user.uid), {
problemStatement,
solution,
techStack,
});

// Save to team document (so all members can see it)
if (userData?.teamName) {
await updateDoc(doc(db, "teams", userData.teamName), {
problemStatement,
solution,
techStack,
});
}
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The save operation updates two documents sequentially without proper transaction handling or permission checking. If the first update succeeds but the second fails, the data will be inconsistent between the user's profile and the team document. Additionally, there's no check to ensure only the team leader can update the problem statement. Consider using a Firestore transaction to ensure both updates succeed or fail together, and add a check to verify the user is the team leader before allowing updates to the team document.

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +92
// Fetch problem statement for team members
if (!response?.problemStatement) {
if (teamInfo.problemStatement) {
setProblemStatement(teamInfo.problemStatement);
setSolution(teamInfo.solution || "");
setTechStack(teamInfo.techStack || "");
setHasProblemStatement(true);
} else if (teamInfo.leaderId) {
// Fallback: Fetch from leader's profile if not on team doc
const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId));
if (leaderDoc.exists()) {
const leaderData = leaderDoc.data();
if (leaderData.problemStatement) {
setProblemStatement(leaderData.problemStatement);
setSolution(leaderData.solution || "");
setTechStack(leaderData.techStack || "");
setHasProblemStatement(true);
}
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for fetching the problem statement is duplicated across multiple conditional branches. The same pattern of setting problemStatement, solution, and techStack appears three times (lines 78-81, 88-91, and earlier in lines 52-57). Consider extracting this into a helper function to improve maintainability and reduce code duplication.

Suggested change
// Fetch problem statement for team members
if (!response?.problemStatement) {
if (teamInfo.problemStatement) {
setProblemStatement(teamInfo.problemStatement);
setSolution(teamInfo.solution || "");
setTechStack(teamInfo.techStack || "");
setHasProblemStatement(true);
} else if (teamInfo.leaderId) {
// Fallback: Fetch from leader's profile if not on team doc
const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId));
if (leaderDoc.exists()) {
const leaderData = leaderDoc.data();
if (leaderData.problemStatement) {
setProblemStatement(leaderData.problemStatement);
setSolution(leaderData.solution || "");
setTechStack(leaderData.techStack || "");
setHasProblemStatement(true);
}
const applyProblemData = (data: any) => {
if (data && data.problemStatement) {
setProblemStatement(data.problemStatement);
setSolution(data.solution || "");
setTechStack(data.techStack || "");
setHasProblemStatement(true);
}
};
// Fetch problem statement for team members
if (!response?.problemStatement) {
if (teamInfo.problemStatement) {
applyProblemData(teamInfo);
} else if (teamInfo.leaderId) {
// Fallback: Fetch from leader's profile if not on team doc
const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId));
if (leaderDoc.exists()) {
const leaderData = leaderDoc.data();
applyProblemData(leaderData);

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +92
if (!response?.problemStatement) {
if (teamInfo.problemStatement) {
setProblemStatement(teamInfo.problemStatement);
setSolution(teamInfo.solution || "");
setTechStack(teamInfo.techStack || "");
setHasProblemStatement(true);
} else if (teamInfo.leaderId) {
// Fallback: Fetch from leader's profile if not on team doc
const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId));
if (leaderDoc.exists()) {
const leaderData = leaderDoc.data();
if (leaderData.problemStatement) {
setProblemStatement(leaderData.problemStatement);
setSolution(leaderData.solution || "");
setTechStack(leaderData.techStack || "");
setHasProblemStatement(true);
}
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition checks if the user doesn't have a problem statement in their profile before fetching from team or leader data. However, if a team leader updates the problem statement after a team member has already loaded their profile data, the team member won't see the update until they reload. This could lead to team members viewing stale problem statement data. Consider removing the condition or adding a mechanism to detect when the team's problem statement has been updated more recently than the user's cached version.

Suggested change
if (!response?.problemStatement) {
if (teamInfo.problemStatement) {
setProblemStatement(teamInfo.problemStatement);
setSolution(teamInfo.solution || "");
setTechStack(teamInfo.techStack || "");
setHasProblemStatement(true);
} else if (teamInfo.leaderId) {
// Fallback: Fetch from leader's profile if not on team doc
const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId));
if (leaderDoc.exists()) {
const leaderData = leaderDoc.data();
if (leaderData.problemStatement) {
setProblemStatement(leaderData.problemStatement);
setSolution(leaderData.solution || "");
setTechStack(leaderData.techStack || "");
setHasProblemStatement(true);
}
if (teamInfo.problemStatement) {
setProblemStatement(teamInfo.problemStatement);
setSolution(teamInfo.solution || "");
setTechStack(teamInfo.techStack || "");
setHasProblemStatement(true);
} else if (teamInfo.leaderId) {
// Fallback: Fetch from leader's profile if not on team doc
const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId));
if (leaderDoc.exists()) {
const leaderData = leaderDoc.data();
if (leaderData.problemStatement) {
setProblemStatement(leaderData.problemStatement);
setSolution(leaderData.solution || "");
setTechStack(leaderData.techStack || "");
setHasProblemStatement(true);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants