diff --git a/cypress/e2e/player/main.cy.ts b/cypress/e2e/player/main.cy.ts index d10ba590..94d428fe 100644 --- a/cypress/e2e/player/main.cy.ts +++ b/cypress/e2e/player/main.cy.ts @@ -11,7 +11,7 @@ import { import { USER_ANSWER_CONTENT } from '../../fixtures/appData'; import { ANSWER_SETTING, QUESTION_SETTING } from '../../fixtures/appSettings'; -describe('player view as reader', () => { +describe('player view as anonymous', () => { beforeEach(() => { cy.setUpApi( { @@ -19,7 +19,7 @@ describe('player view as reader', () => { }, { context: Context.Player, - permission: PermissionLevel.Read, + memberId: undefined, }, ); cy.visit(`/`); @@ -51,7 +51,7 @@ describe('player view as reader', () => { }); }); -describe('player view as writer', () => { +describe('player view as reader', () => { beforeEach(() => { cy.setUpApi( { @@ -59,7 +59,7 @@ describe('player view as writer', () => { }, { context: Context.Player, - permission: PermissionLevel.Write, + permission: PermissionLevel.Read, }, ); cy.visit(`/`); diff --git a/src/modules/main/PlayerView.tsx b/src/modules/main/PlayerView.tsx index dc009fa8..cc8b7b8b 100644 --- a/src/modules/main/PlayerView.tsx +++ b/src/modules/main/PlayerView.tsx @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'; import { Box, Grid, TextField, Typography } from '@mui/material'; import { useLocalContext } from '@graasp/apps-query-client'; -import { AppData, PermissionLevel } from '@graasp/sdk'; +import { AppData } from '@graasp/sdk'; import isEqual from 'lodash.isequal'; import sortBy from 'lodash.sortby'; @@ -22,7 +22,7 @@ function isAnswer(appData: AppData): boolean { const PlayerView = (): JSX.Element => { const { t } = useTranslation('translations', { keyPrefix: 'PLAYER' }); - const { permission } = useLocalContext(); + const { memberId } = useLocalContext(); const { question, // answer: answerSavedState, @@ -46,20 +46,21 @@ const PlayerView = (): JSX.Element => { const [answer, setAnswer] = useState(savedAnswer); const disableSave = useMemo(() => { - // disable if permission is read - if (permission === PermissionLevel.Read) { + // disable if there is no user (logged out or anonymous) + if (!memberId) { return true; } // disable if answer is equal return isEqual(savedAnswer, answer); - }, [answer, savedAnswer, permission]); + }, [answer, savedAnswer, memberId]); const disabledMessage = useMemo(() => { - if (permission === PermissionLevel.Read) { + // disable if there is no user (logged out or anonymous) + if (!memberId) { return t('SAVE_BUTTON'); } return t('SAVED_MESSAGE'); - }, [permission, t]); + }, [memberId, t]); const handleChangeAnswer = (event: ChangeEvent): void => { const { value } = event.target;