Skip to content

teams: smoother survey demographics handling (fixes #9983)#9984

Merged
dogi merged 8 commits into
masterfrom
9983-public-survey-demographics
Jun 18, 2026
Merged

teams: smoother survey demographics handling (fixes #9983)#9984
dogi merged 8 commits into
masterfrom
9983-public-survey-demographics

Conversation

@Mutugiii

@Mutugiii Mutugiii commented Jun 9, 2026

Copy link
Copy Markdown
Member

Fixes #9983

Add the optional demographics information form at the end of public surveys

image

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b14d20bea8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/app/exams/public-surveys/public-survey.component.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an optional demographics step (birth year + gender) after completing a public survey, and sends the sanitized demographics payload through to the gateway so it can be stored with the public submission.

Changes:

  • Frontend: introduce a post-survey demographics UI step and include demographics in the public survey submission payload.
  • Frontend: refactor inline component styles into a dedicated SCSS file.
  • Gateway: accept and sanitize optional user demographics fields (age, gender) when creating public survey submissions.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/app/exams/public-surveys/public-surveys.service.ts Extends submitSurvey to optionally include demographics (user) in the POST body.
src/app/exams/public-surveys/public-survey.component.ts Adds demographics form + navigation flow; builds optional demographics payload for submission.
src/app/exams/public-surveys/public-survey.component.scss New stylesheet for state views and demographics form layout.
src/app/exams/public-surveys/public-survey.component.html Adds demographics step UI; updates navigation buttons to route to demographics before submission.
gateway/src/modules/public/services/surveys.service.ts Extends payload typing and sanitizes stored submission user demographics fields.

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

Comment thread src/app/exams/public-surveys/public-survey.component.ts
@Mutugiii

Mutugiii commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f88084cce4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/app/exams/public-surveys/public-survey.component.html Outdated
@Mutugiii Mutugiii requested a review from paulbert June 9, 2026 12:20
@paulbert

paulbert commented Jun 11, 2026

Copy link
Copy Markdown
Member

Tried a couple of times, but I'm not seeing the info from that form being reflected in the data export. The last two entries were made with this branch.

image

UPDATE: I see there were changes to the planet gateway service. Using the image from this branch fixes that issue.

@paulbert paulbert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like it's working as expected, nice work!

I've got some comments on error handling, formatting, and code quality, but I'll go ahead and approve.

const age = user.age;
const gender = typeof user.gender === 'string' ? user.gender.trim() : '';

if (typeof age === 'number' && Number.isInteger(age) && age >= 0 && age <= 130) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should at least log if not throw something if age is in the payload and not in the correct range.

I think in the frontend this is limited by a minimum year, not maximum age as well. Not ideal to have the mismatch here as in a few years a valid form value will be removed here. Also frontend rejects age 0, but this would accept that.

sanitizedUser.age = age;
}

if (gender === 'male' || gender === 'female') {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above, log or throw an error if the value exists and is invalid.

</div>
</planet-exams-question-frame>

<div *ngIf="survey && showDemographics && !isSubmitted" class="state-view">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason why this form has the fields flipped from the "Record Survey" version?

Generally not ideal that this is duplicated from that, but I see that is also a bit entangled with the UsersUpdateComponent so I think this is OK.

readonly answer = new FormControl<ExamAnswerValue>(null, { validators: examAnswerValidator });
readonly demographicsForm = this.fb.group({
birthYear: this.fb.control<number | null>(null, [
Validators.min(1900),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be cleaner with the backend to match this to the current year minus 130 rather than a minimum year.

user.gender = gender;
}

return Object.keys(user).length > 0 ? user : undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you should just return the user here. There's no check from here to the database on whether the user object is undefined other than to turn it into an empty object if it is.

By explicitly setting it to undefined if it's an empty object, you're setting an expectation that that matters somewhere in the application.

@dogi dogi added the priority label Jun 18, 2026
@dogi dogi changed the title teams: add public survey demographics info form (fixes #9983) teams: smoother survey demographics handling (fixes #9983) Jun 18, 2026
@dogi dogi merged commit a6369c7 into master Jun 18, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add optional demographics form to public surveys

4 participants