Skip to content

Commit

Permalink
Support anonymized survey submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
eikhr committed Sep 24, 2024
1 parent e7e0f6c commit 2c35c69
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
7 changes: 3 additions & 4 deletions app/reducers/surveySubmissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ const { selectByField: selectSurveySubmissionsByField } =
export const selectSurveySubmissionsBySurveyId =
selectSurveySubmissionsByField('survey');

export const selectSurveySubmissionForUser = createSelector(
export const selectOwnSurveySubmission = createSelector(
(state: RootState, props: { surveyId: EntityId }) =>
selectSurveySubmissionsBySurveyId(state, props.surveyId),
(_: RootState, props: { currentUserId: EntityId }) => props.currentUserId,
(submissions, userId) =>
submissions.find((surveySubmission) => surveySubmission.user === userId),
(submissions) =>
submissions.find((surveySubmission) => surveySubmission.isOwner),
);

export const useFetchedSurveySubmissions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'app/actions/SurveySubmissionActions';
import Time from 'app/components/Time';
import { useCurrentUser } from 'app/reducers/auth';
import { selectSurveySubmissionForUser } from 'app/reducers/surveySubmissions';
import { selectOwnSurveySubmission } from 'app/reducers/surveySubmissions';
import { useFetchedSurvey } from 'app/reducers/surveys';
import AlreadyAnswered from 'app/routes/surveys/components/AddSubmission/AlreadyAnswered';
import SurveySubmissionForm from 'app/routes/surveys/components/AddSubmission/SurveySubmissionForm';
Expand All @@ -27,13 +27,10 @@ const AddSubmissionPage = () => {
useParams<AddSubmissionPageParams>() as AddSubmissionPageParams;
const currentUser = useCurrentUser();
const { survey, event } = useFetchedSurvey('addSubmission', surveyId);
const submission = useAppSelector(
(state) =>
currentUser &&
selectSurveySubmissionForUser(state, {
surveyId: Number(surveyId),
currentUserId: currentUser.id,
}),
const submission = useAppSelector((state) =>
selectOwnSurveySubmission(state, {
surveyId: Number(surveyId),
}),
);

const fetchingSubmission = useAppSelector(
Expand Down
2 changes: 1 addition & 1 deletion app/store/models/SurveySubmission.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {

export interface SurveySubmission {
id: EntityId;
user: EntityId;
isOwner: boolean;
survey: EntityId;
answers: (SurveyAnswer | AdminSurveyAnswer)[];
}
Expand Down

0 comments on commit 2c35c69

Please sign in to comment.