mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-11-01 18:19:43 +00:00
feat(admin): preview response media
Show who-likely choices in human terms and provide protected photo and audio previews in activity and user response views. Fetch media by response ID through an authenticated Edge Function that enforces the view_responses permission.
This commit is contained in:
1 parent
7545289dd3
commit
650c81856f
8 files changed
+385
-3
No files matched your search
@@ -24,4 +24,20 @@ describe('admin question response formatting', () => {
|
||||
it('labels non-swipe matches', () => {
|
||||
expect(MATCH_TYPE_LABELS.both_answered).toBe('Both Answered');
|
||||
});
|
||||
|
||||
it('shows who was chosen without exposing user identifiers', () => {
|
||||
expect(formatAdminResponse(
|
||||
'who_likely',
|
||||
'yes',
|
||||
{ type: 'who_likely', chosen_user_id: 'user-1' },
|
||||
{ responderId: 'user-1', responderName: 'Alex' },
|
||||
)).toEqual({ label: 'Chose themselves', detail: 'Alex chose themselves' });
|
||||
|
||||
expect(formatAdminResponse(
|
||||
'who_likely',
|
||||
'yes',
|
||||
{ type: 'who_likely', chosen_user_id: 'user-2' },
|
||||
{ responderId: 'user-1', responderName: 'Alex' },
|
||||
)).toEqual({ label: 'Chose their partner', detail: 'Alex chose their partner' });
|
||||
});
|
||||
});
|
||||
@@ -31,6 +31,7 @@ export function formatAdminResponse(
|
||||
questionType: QuestionType | null | undefined,
|
||||
answer: AnswerType,
|
||||
responseData: AdminResponseData,
|
||||
context?: { responderId?: string; responderName?: string | null },
|
||||
): { label: string; detail: string | null } {
|
||||
const resolvedType = resolveQuestionType(questionType);
|
||||
|
||||
@@ -63,5 +64,27 @@ export function formatAdminResponse(
|
||||
return { label: 'Photo submitted', detail: null };
|
||||
}
|
||||
|
||||
const chosenUserId = responseData && 'chosen_user_id' in responseData
|
||||
&& typeof responseData.chosen_user_id === 'string'
|
||||
? responseData.chosen_user_id
|
||||
: null;
|
||||
const choseSelf = chosenUserId && context?.responderId
|
||||
? chosenUserId === context.responderId
|
||||
: null;
|
||||
|
||||
if (choseSelf === true) {
|
||||
return {
|
||||
label: 'Chose themselves',
|
||||
detail: context?.responderName ? `${context.responderName} chose themselves` : null,
|
||||
};
|
||||
}
|
||||
|
||||
if (choseSelf === false) {
|
||||
return {
|
||||
label: 'Chose their partner',
|
||||
detail: context?.responderName ? `${context.responderName} chose their partner` : null,
|
||||
};
|
||||
}
|
||||
|
||||
return { label: 'Choice submitted', detail: null };
|
||||
}
|
||||
Reference in new issue
Block a user