diff --git a/src/components/Action/ActionBegin/ActionBegin.tsx b/src/components/Action/ActionBegin/ActionBegin.tsx index 50281d6965e06d6d98e6d0653ae37a159d685318..f9cdae3e552e1e9e89dbdfc02d0b8fb285f5df7e 100644 --- a/src/components/Action/ActionBegin/ActionBegin.tsx +++ b/src/components/Action/ActionBegin/ActionBegin.tsx @@ -40,18 +40,23 @@ const ActionBegin = ({ useEffect(() => { let subscribed = true const getAction = async () => { - if (action) { - if (subscribed) setCurrentAction(action) - } else { - const actionService = new ActionService(client) - let actions: Ecogesture[] = [] - if (isProfileTypeCompleted) { - actions = await actionService.getCustomActions(fluidTypes) + if (subscribed) { + if (action) { + setCurrentAction(action) + const icon = await importIconById(action.id, 'ecogesture') + setActionIcon(icon || defaultIcon) } else { - actions = await actionService.getDefaultActions() - } - if (subscribed) { + const actionService = new ActionService(client) + let actions: Ecogesture[] = [] + if (isProfileTypeCompleted) { + actions = await actionService.getCustomActions(fluidTypes) + } else { + actions = await actionService.getDefaultActions() + } + setCurrentAction(actions[0]) + const icon = await importIconById(actions[0].id, 'ecogesture') + setActionIcon(icon || defaultIcon) } } } @@ -61,16 +66,6 @@ const ActionBegin = ({ } }, [action, client, fluidTypes, isProfileTypeCompleted]) - useEffect(() => { - async function handleEcogestureIcon() { - if (currentAction) { - const icon = await importIconById(currentAction.id, 'ecogesture') - setActionIcon(icon || defaultIcon) - } - } - handleEcogestureIcon() - }, [currentAction]) - return ( <div className="action-begin"> {currentAction && ( diff --git a/src/components/Action/ActionChoose/__snapshots__/ActionChoose.spec.tsx.snap b/src/components/Action/ActionChoose/__snapshots__/ActionChoose.spec.tsx.snap index 07ca33e2f1dac1835822ac668fee8ee5fbe887ed..972120fc6cbd97a5941b146281b3b840ce9628ab 100644 --- a/src/components/Action/ActionChoose/__snapshots__/ActionChoose.spec.tsx.snap +++ b/src/components/Action/ActionChoose/__snapshots__/ActionChoose.spec.tsx.snap @@ -21,7 +21,7 @@ exports[`ActionChoose component should render correctly 1`] = ` width="100" > <use - xlink:href="#" + xlink:href="#test-file-stub" /> </svg> </div> diff --git a/src/components/Action/ActionList/ActionList.tsx b/src/components/Action/ActionList/ActionList.tsx index b79e28bc2c2ebf569577c2506278007f063d01a9..4de937d4c78d4e6741f67eccfde57092f139ff63 100644 --- a/src/components/Action/ActionList/ActionList.tsx +++ b/src/components/Action/ActionList/ActionList.tsx @@ -43,16 +43,14 @@ const ActionList = ({ setSelectedAction, setShowList }: ActionListProps) => { <> {actions && ( <div className="action-list-container"> - {actions.map(action => { - return ( - <ActionCard - key={action.id} - action={action} - setSelectedAction={setSelectedAction} - setShowList={setShowList} - /> - ) - })} + {actions.map(action => ( + <ActionCard + key={action.id} + action={action} + setSelectedAction={setSelectedAction} + setShowList={setShowList} + /> + ))} </div> )} </> diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx index 44bcc2b670387f373045c72260cf6ce98635aa75..fa2c357fbb80de311e2ac2865b6d907855de176f 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx @@ -127,7 +127,7 @@ const ElecHalfHourMonthlyAnalysis = ({ let subscribed = true const fluidsPricesService = new FluidPricesService(client) async function getAllLastPrices() { - const price: FluidPrice = await fluidsPricesService.getPrices( + const price = await fluidsPricesService.getPrices( FluidType.ELECTRICITY, analysisMonth.minus({ month: 1 }) ) diff --git a/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.tsx b/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.tsx index 42429b5af412be83452c3d86aceef5db57b6677a..46656f1f9406b307455512e596f4ddeddb8941a5 100644 --- a/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.tsx +++ b/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.tsx @@ -16,6 +16,7 @@ import React, { useEffect, useRef, useState } from 'react' import ConsumptionDataManager from 'services/consumption.service' import { setSelectedDate } from 'store/chart/chart.slice' import { useAppDispatch, useAppSelector } from 'store/hooks' +import { getFluidName } from 'utils/utils' import './maxConsumptionCard.scss' const MaxConsumptionCard = ({ @@ -29,22 +30,15 @@ const MaxConsumptionCard = ({ const { analysisMonth } = useAppSelector(state => state.ecolyo.analysis) const [isLoading, setIsLoading] = useState<boolean>(false) const [maxDayData, setMaxDayData] = useState<Dataload | null>(null) + const [currentFluid, setCurrentFluid] = useState<FluidType>(fluidsWithData[0]) const [chartData, setChartData] = useState<Datachart>({ actualData: [], comparisonData: null, }) const containerRef = useRef<HTMLDivElement>(null) const { height, width } = useChartResize(containerRef, isLoading, 250, 940) - const [currentFluid, setCurrentFluid] = useState<FluidType | undefined>() - useEffect(() => { - setCurrentFluid(fluidsWithData[0]) - }, [fluidsWithData]) - - const currentFluidSlug = FluidType[currentFluid || 0] as - | 'ELECTRICITY' - | 'WATER' - | 'GAZ' + const fluidName = getFluidName(currentFluid || FluidType.ELECTRICITY) const handleFluidChange = (direction: number) => { if (currentFluid === undefined) return @@ -135,8 +129,8 @@ const MaxConsumptionCard = ({ <div className="text-16-normal title">{t('analysis.max_day')}</div> <div className="fluid-navigation"> {buttonPrev()} - <div className={`text-20-bold fluid ${currentFluidSlug.toLowerCase()}`}> - {t(`FLUID.${currentFluidSlug}.LABEL`)} + <div className={`text-20-bold fluid ${fluidName}`}> + {t(`FLUID.${fluidName.toUpperCase()}.LABEL`)} </div> {buttonNext()} </div> diff --git a/src/components/Analysis/ProfileComparator/ProfileComparator.tsx b/src/components/Analysis/ProfileComparator/ProfileComparator.tsx index 23e00858b499b9f757f2832af1a12482b3f1a3d5..501191f56856c0d1265466308d8339b0af701604 100644 --- a/src/components/Analysis/ProfileComparator/ProfileComparator.tsx +++ b/src/components/Analysis/ProfileComparator/ProfileComparator.tsx @@ -14,7 +14,7 @@ import { useClient } from 'cozy-client' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import Icon from 'cozy-ui/transpiled/react/Icon' import { FluidType } from 'enums' -import { MonthlyForecast, PerformanceIndicator, ProfileType } from 'models' +import { MonthlyForecast, PerformanceIndicator } from 'models' import React, { useCallback, useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' import ProfileTypeService from 'services/profileType.service' @@ -35,7 +35,6 @@ const ProfileComparator = ({ const { t } = useI18n() const client = useClient() const navigate = useNavigate() - const userPriceConsumption: number = aggregatedPerformanceIndicator.value || 0 const { analysis: { analysisMonth }, profile, @@ -43,8 +42,10 @@ const ProfileComparator = ({ const [homePriceConsumption, setHomePriceConsumption] = useState<number>(0) const [forecast, setForecast] = useState<MonthlyForecast | null>(null) const [isLoading, setIsLoading] = useState<boolean>(true) - const [activeAverageHome, setActiveAverageHome] = useState<boolean>(false) + + const userPriceConsumption = aggregatedPerformanceIndicator.value || 0 + const toggleAccordion = () => { setActiveAverageHome(prev => !prev) if (!activeAverageHome) { @@ -93,19 +94,18 @@ const ProfileComparator = ({ async function loadAverageConsumption() { const analysisDate = analysisMonth.minus({ month: 1 }).startOf('month') const profileTypeEntityService = new ProfileTypeEntityService(client) - const profileType: ProfileType | null = + const profileType = await profileTypeEntityService.getProfileType(analysisDate) if (profileType !== null) { - const profileTypeService: ProfileTypeService = new ProfileTypeService( + const profileTypeService = new ProfileTypeService( profileType, client, analysisMonth.minus({ month: 1 }).year ) - const monthlyForecast: MonthlyForecast = - await profileTypeService.getMonthlyForecast( - analysisDate.year, - analysisDate.month - ) + const monthlyForecast = await profileTypeService.getMonthlyForecast( + analysisDate.year, + analysisDate.month + ) if (subscribed) { setForecast(monthlyForecast) if (monthlyForecast) { diff --git a/src/components/Analysis/TotalAnalysisChart/PieChart.tsx b/src/components/Analysis/TotalAnalysisChart/PieChart.tsx index ad96a96122221cf037ac4e0ab48d0bb088e6e7cb..12b27e060930b5b345f1b0149ef4b53a144a3fc5 100644 --- a/src/components/Analysis/TotalAnalysisChart/PieChart.tsx +++ b/src/components/Analysis/TotalAnalysisChart/PieChart.tsx @@ -23,7 +23,7 @@ const PieChart = ({ const arcWidth = outerRadius - innerRadius useEffect(() => { - const dataloadArray: number[] = dataloadValueDetailArray.map( + const dataloadArray = dataloadValueDetailArray.map( dataload => dataload.value ) const data = createPie(dataloadArray) diff --git a/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.tsx b/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.tsx index 83926cbe364a54b9e8a17c80d1e5f80bcf32429e..a33ba27feaa1d76183d5a6143f5e686e77f2ace9 100644 --- a/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.tsx +++ b/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.tsx @@ -25,12 +25,12 @@ const ChallengeCardUnlocked = ({ global: { fluidTypes, fluidStatus }, } = useAppSelector(state => state.ecolyo) const dispatch = useAppDispatch() - const [openNoFluidModal, setopenNoFluidModal] = useState(false) + const [openNoFluidModal, setOpenNoFluidModal] = useState(false) const [challengeIcon, setChallengeIcon] = useState(defaultIcon) let statusRequirementOk = false const toggleNoFluidModal = useCallback(() => { - setopenNoFluidModal(prev => !prev) + setOpenNoFluidModal(prev => !prev) }, []) fluidStatus.forEach(fluid => { diff --git a/src/components/Connection/EPGLConnect/EpglConnectModal/EpglConnectModal.tsx b/src/components/Connection/EPGLConnect/EpglConnectModal/EpglConnectModal.tsx index 55b005d968e4bef248b72f1c4fab45344751a164..3638cc07d8486793bf1d00b9054ed67a6b7ba377 100644 --- a/src/components/Connection/EPGLConnect/EpglConnectModal/EpglConnectModal.tsx +++ b/src/components/Connection/EPGLConnect/EpglConnectModal/EpglConnectModal.tsx @@ -3,7 +3,7 @@ import CloseIcon from 'assets/icons/ico/close.svg' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import Icon from 'cozy-ui/transpiled/react/Icon' import { FluidType } from 'enums' -import React, { useEffect, useState } from 'react' +import React, { useState } from 'react' import { useAppSelector } from 'store/hooks' import './PartnerConnectModal.scss' import EpglCreateAccount from './Steps/EpglCreateAccount' @@ -40,13 +40,8 @@ const EpglConnectModal = ({ const [currentStep, setCurrentStep] = useState(StepEnum.DoYouHaveAccount) - useEffect(() => { - if (open) { - setCurrentStep(0) - } - }, [open]) - const handleCloseModal = () => { + setCurrentStep(StepEnum.DoYouHaveAccount) setOpenModal(false) } diff --git a/src/components/Duel/DuelChart/DuelChart.tsx b/src/components/Duel/DuelChart/DuelChart.tsx index 993328d4911ba67af59cc6318e38ef791c96301a..e0baa475bf6673b4d7b6e9b89fd305e2c0ecc8f7 100644 --- a/src/components/Duel/DuelChart/DuelChart.tsx +++ b/src/components/Duel/DuelChart/DuelChart.tsx @@ -1,7 +1,7 @@ import DuelBar from 'components/Duel/DuelChart/DuelBar' import { TimeStep } from 'enums' import { Dataload, UserChallenge } from 'models' -import React, { useEffect, useState } from 'react' +import React from 'react' import './duelChart.scss' interface DuelChartProps { @@ -17,11 +17,8 @@ const DuelChart = ({ width, height, }: DuelChartProps) => { - const [average, setAverage] = useState<number>(0) - - useEffect(() => { - setAverage(userChallenge.duel.threshold / userChallenge.duel.duration.days) - }, [userChallenge.duel.duration.days, userChallenge.duel.threshold]) + const average = + userChallenge.duel.threshold / userChallenge.duel.duration.days return ( <div className="fs-slide"> diff --git a/src/components/Duel/DuelEmptyValueModal/DuelEmptyValueModal.tsx b/src/components/Duel/DuelEmptyValueModal/DuelEmptyValueModal.tsx index 70e1f0261ac08777fe51fd2e49d15184c91da5a0..dd86dc0108170aad9557cd376125248668685ba5 100644 --- a/src/components/Duel/DuelEmptyValueModal/DuelEmptyValueModal.tsx +++ b/src/components/Duel/DuelEmptyValueModal/DuelEmptyValueModal.tsx @@ -18,6 +18,7 @@ const DuelEmptyValueModal = ({ }: DuelEmptyValueModalProps) => { const { t } = useI18n() const [emptyIcon, setEmptyIcon] = useState<string>(defaultIcon) + useEffect(() => { async function handleEcogestureIcon() { const icon = await importIconById('emptyValue', 'duel') diff --git a/src/components/Duel/DuelOngoing/DuelOngoing.tsx b/src/components/Duel/DuelOngoing/DuelOngoing.tsx index e5f8335b43654c066cdb4492f4835e49ae55884d..c2ec10acbfb57e60e5e9e654664c6fa9f0d87b65 100644 --- a/src/components/Duel/DuelOngoing/DuelOngoing.tsx +++ b/src/components/Duel/DuelOngoing/DuelOngoing.tsx @@ -104,7 +104,7 @@ const DuelOngoing = ({ userChallenge, isFinished }: DuelOngoingProps) => { let subscribed = true async function populateData() { if (isFinished) { - const dataloads: Dataload[] = + const dataloads = await challengeService.getUserChallengeDataload(userChallenge) if (subscribed) { setFinishedDataLoad(dataloads) diff --git a/src/components/Duel/DuelUnlocked/DuelUnlocked.tsx b/src/components/Duel/DuelUnlocked/DuelUnlocked.tsx index eb4ddcd86952d5ccb0eb188ceb51b8ec497ab27a..ad7693384a06ee8fcac0ac25b9e09d76896b5689 100644 --- a/src/components/Duel/DuelUnlocked/DuelUnlocked.tsx +++ b/src/components/Duel/DuelUnlocked/DuelUnlocked.tsx @@ -19,11 +19,9 @@ const DuelUnlocked = ({ userChallenge }: { userChallenge: UserChallenge }) => { const dispatch = useAppDispatch() const [duelIcon, setDuelIcon] = useState(defaultIcon) - const average: string = formatNumberValues( - userChallenge.duel.threshold - ).toString() - const duration: string = userChallenge.duel.duration.days.toString() - const description: string = userChallenge.duel.description + const average = formatNumberValues(userChallenge.duel.threshold).toString() + const duration = userChallenge.duel.duration.days.toString() + const description = userChallenge.duel.description .replace('#CONSUMPTION', average) .replace('#DURATION', duration) diff --git a/src/components/FluidChart/FluidChartSwipe.tsx b/src/components/FluidChart/FluidChartSwipe.tsx index 934e86468f5da625b27ff521a5ef50921edffb37..846e0225eaeb34347e08c1439d64d14ccac4bcb0 100644 --- a/src/components/FluidChart/FluidChartSwipe.tsx +++ b/src/components/FluidChart/FluidChartSwipe.tsx @@ -54,7 +54,7 @@ const FluidChartSwipe = ({ fluidType }: { fluidType: FluidType }) => { useEffect(() => { function initIndex() { const dateChartService = new DateChartService() - const updatedIndex: number = dateChartService.defineDateIndex( + const updatedIndex = dateChartService.defineDateIndex( currentTimeStep, selectedDate ) diff --git a/src/components/Hooks/useUserInstanceSettings.tsx b/src/components/Hooks/useUserInstanceSettings.tsx index 8868e24e1312dbf1de8c01807568eb030cdd23fa..5a8ec683892a3858ad9bf979d4038a535dc317b7 100644 --- a/src/components/Hooks/useUserInstanceSettings.tsx +++ b/src/components/Hooks/useUserInstanceSettings.tsx @@ -1,15 +1,30 @@ +import * as Sentry from '@sentry/react' import { useClient } from 'cozy-client' import get from 'lodash/get' -import { UserInstanceSettings, UserInstanceSettingsAttributes } from 'models' import { useEffect, useState } from 'react' -const useUserInstanceSettings = (): UserInstanceSettings => { +interface UserInstanceSettingsAttributes { + auth_mode?: string + auto_update?: boolean + context?: string + email?: string + locale?: string + oidc_id?: string + onboarding_finished?: boolean + public_name: string + tos?: string + tos_latest?: string + uuid?: string +} + +const useUserInstanceSettings = (): { + data: UserInstanceSettingsAttributes +} => { const client = useClient() const [settings, setSettings] = useState<UserInstanceSettingsAttributes>({ // eslint-disable-next-line camelcase public_name: '', }) - const [fetchStatus, setFetchStatus] = useState<string>('idle') useEffect(() => { const fetchData = async () => { @@ -18,9 +33,9 @@ const useUserInstanceSettings = (): UserInstanceSettings => { .getStackClient() .fetchJSON('GET', '/settings/instance') setSettings(get(response, 'data.attributes')) - setFetchStatus('loaded') } catch (error) { - setFetchStatus('failed') + console.error(error) + Sentry.captureException(error) } } fetchData() @@ -28,7 +43,6 @@ const useUserInstanceSettings = (): UserInstanceSettings => { return { data: settings, - fetchStatus, } } diff --git a/src/components/Quiz/QuizExplanationModal/QuizExplanationModal.tsx b/src/components/Quiz/QuizExplanationModal/QuizExplanationModal.tsx index 928940f0642c7398a5ddd3dbe4b0aa883c5ccd0a..2d84331434722f315a25f5fe8489f12bb180e19f 100644 --- a/src/components/Quiz/QuizExplanationModal/QuizExplanationModal.tsx +++ b/src/components/Quiz/QuizExplanationModal/QuizExplanationModal.tsx @@ -5,12 +5,12 @@ import wrongAnswer from 'assets/icons/ico/wrongAnswer.svg' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import Icon from 'cozy-ui/transpiled/react/Icon' import { QuestionEntity } from 'models' -import React, { useEffect, useState } from 'react' +import React from 'react' import './quizExplanationModal.scss' interface QuizExplanationModalProps { open: boolean - question: QuestionEntity | undefined + question: QuestionEntity answerIndex: number goNext: () => void handleCloseClick: () => void @@ -24,15 +24,9 @@ const QuizExplanationModal = ({ handleCloseClick, }: QuizExplanationModalProps) => { const { t } = useI18n() - const [validAnswer, setValidAnswer] = useState<number>(0) - useEffect(() => { - if (question) { - const resultIndex: number = question.answers.findIndex( - answer => answer.isTrue - ) - setValidAnswer(resultIndex) - } - }, [question]) + + const validAnswer = question.answers.findIndex(answer => answer.isTrue) + return ( <Dialog open={open} diff --git a/src/components/Quiz/QuizQuestion/QuizQuestion.spec.tsx b/src/components/Quiz/QuizQuestion/QuizQuestion.spec.tsx index 6abd2f50f97ab01603e316fce1d83ff8ddf201d8..311ec78e7b1f38a7711fd3a7df48b1bd8650c568 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestion.spec.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestion.spec.tsx @@ -1,17 +1,18 @@ import { render, waitFor } from '@testing-library/react' import { UserQuestionState } from 'enums' +import { QuestionEntity } from 'models' import React from 'react' import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import QuizQuestion from './QuizQuestion' +const mockGetCustomQuestion = jest.fn<Promise<QuestionEntity>, [string]>() + jest.mock('services/quiz.service', () => { - return jest.fn(() => { - return { - getCustomQuestion: jest.fn(), - } - }) + return jest.fn(() => ({ + getCustomQuestion: mockGetCustomQuestion, + })) }) jest.mock( @@ -45,6 +46,21 @@ describe('QuizQuestion component', () => { updateUserChallengeData.quiz.questions.forEach( answer => (answer.result = UserQuestionState.CORRECT) ) + mockGetCustomQuestion.mockResolvedValue({ + questionLabel: 'customQuestion', + explanation: 'explanation', + answers: [ + { + answerLabel: 'answer1', + isTrue: true, + }, + { + answerLabel: 'answer2', + isTrue: false, + }, + ], + source: 'source', + }) const { container } = render( <Provider store={store}> <QuizQuestion userChallenge={updateUserChallengeData} /> diff --git a/src/components/Quiz/QuizQuestion/QuizQuestion.tsx b/src/components/Quiz/QuizQuestion/QuizQuestion.tsx index 25ff5662bdd27baa282c522037a2e2178f939c50..4838694dc56013f3fbaba7af56b402b2bae8cfc9 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestion.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestion.tsx @@ -10,17 +10,15 @@ import './quizQuestion.scss' const QuizQuestion = ({ userChallenge }: { userChallenge: UserChallenge }) => { const client = useClient() - const { fluidTypes } = useAppSelector(state => state.ecolyo.global) const navigate = useNavigate() - const questionsIsLocked: boolean = userChallenge.quiz.questions.some( + const { fluidTypes } = useAppSelector(state => state.ecolyo.global) + + const questionsIsLocked = userChallenge.quiz.questions.some( answer => answer.result == 0 ) - const [question, setQuestion] = useState<QuestionEntity>() - const [isCustomQuest, setIsCustomQuest] = useState<boolean>( - !questionsIsLocked - ) - const [customQuestionLoading, setCustomQuestionLoading] = - useState<boolean>(false) + const [customQuestion, setCustomQuestion] = useState<QuestionEntity>() + const [isCustomQuest, setIsCustomQuest] = useState(!questionsIsLocked) + const [customQuestionLoading, setCustomQuestionLoading] = useState(false) const goBack = () => { navigate('/challenges') @@ -29,14 +27,13 @@ const QuizQuestion = ({ userChallenge }: { userChallenge: UserChallenge }) => { useEffect(() => { let subscribed = true async function loadCustomQuestion() { - const quizService: QuizService = new QuizService(client) - const customQuestion: QuestionEntity = - await quizService.getCustomQuestion( - userChallenge.quiz.customQuestion, - fluidTypes - ) + const quizService = new QuizService(client) + const customQuestion = await quizService.getCustomQuestion( + userChallenge.quiz.customQuestion, + fluidTypes + ) if (subscribed) { - setQuestion(customQuestion) + setCustomQuestion(customQuestion) setCustomQuestionLoading(false) } } @@ -51,11 +48,11 @@ const QuizQuestion = ({ userChallenge }: { userChallenge: UserChallenge }) => { return ( <> - {isCustomQuest ? ( + {isCustomQuest && customQuestion ? ( <QuizQuestionContentCustom userChallenge={userChallenge} goBack={goBack} - question={question} + customQuestion={customQuestion} isLoading={customQuestionLoading} /> ) : ( diff --git a/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx b/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx index 5a3c5f3dc6117b1546bd6c73ad10765b158f530e..f467eb0beb84762b48d9741ae55403f663e06c60 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx @@ -36,7 +36,7 @@ describe('QuizCustomQuestionContent component', () => { <Provider store={store}> <QuizQuestionContentCustom userChallenge={userChallengeData[0]} - question={questionEntity} + customQuestion={questionEntity} goBack={mockHistoryPush('/challenges')} isLoading={false} /> @@ -54,7 +54,7 @@ describe('QuizCustomQuestionContent component', () => { <Provider store={store}> <QuizQuestionContentCustom userChallenge={userChallengeData[0]} - question={questionEntity} + customQuestion={questionEntity} goBack={mockHistoryPush('/challenges')} isLoading={true} /> @@ -69,7 +69,7 @@ describe('QuizCustomQuestionContent component', () => { <Provider store={store}> <QuizQuestionContentCustom userChallenge={userChallengeData[0]} - question={questionEntity} + customQuestion={questionEntity} goBack={mockHistoryPush('/challenges')} isLoading={false} /> diff --git a/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.tsx b/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.tsx index f37f638feef599af138a08aab4538c714f7485f3..8e08ef5adf4be828e82f3b7c35296e20dbc76f91 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.tsx @@ -17,14 +17,14 @@ import './quizQuestion.scss' interface QuizQuestionContentCustomProps { userChallenge: UserChallenge goBack: () => void - question: QuestionEntity | undefined + customQuestion: QuestionEntity isLoading: boolean } const QuizQuestionContentCustom = ({ userChallenge, goBack, - question, + customQuestion, isLoading, }: QuizQuestionContentCustomProps) => { const { t } = useI18n() @@ -38,27 +38,25 @@ const QuizQuestionContentCustom = ({ const challengeService = new ChallengeService(client) const validateQuestion = async () => { - if (question) { - const resultIndex = question.answers.findIndex( - answer => answer.answerLabel === userChoice - ) - setAnswerIndex(resultIndex) - setOpenModal(true) + const resultIndex = customQuestion.answers.findIndex( + answer => answer.answerLabel === userChoice + ) + setAnswerIndex(resultIndex) + setOpenModal(true) - const result = question.answers.filter( - answer => answer.answerLabel === userChoice - ) - const quizUpdated = await quizService.updateUserQuiz( - userChallenge.quiz, - result[0].isTrue - ) - const userChallengeUpdated = await challengeService.updateUserChallenge( - userChallenge, - UserChallengeUpdateFlag.QUIZ_UPDATE, - quizUpdated - ) - dispatch(updateUserChallengeList(userChallengeUpdated)) - } + const result = customQuestion.answers.filter( + answer => answer.answerLabel === userChoice + ) + const quizUpdated = await quizService.updateUserQuiz( + userChallenge.quiz, + result[0].isTrue + ) + const userChallengeUpdated = await challengeService.updateUserChallenge( + userChallenge, + UserChallengeUpdateFlag.QUIZ_UPDATE, + quizUpdated + ) + dispatch(updateUserChallengeList(userChallengeUpdated)) } const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { @@ -92,27 +90,25 @@ const QuizQuestionContentCustom = ({ <Loader /> </div> ) : ( - question && ( - <> - <p className="question text-18-bold">{question.questionLabel}</p> - {question.answers.map((answer, index) => { - return ( - <div className="answer" key={index}> - <input - type="radio" - id={`answer${index}`} - value={answer.answerLabel} - onChange={handleChange} - checked={userChoice === answer.answerLabel} - /> - <label htmlFor={`answer${index}`} className="text-16-bold"> - {answer.answerLabel} - </label> - </div> - ) - })} - </> - ) + <> + <p className="question text-18-bold"> + {customQuestion.questionLabel} + </p> + {customQuestion.answers.map((answer, index) => ( + <div className="answer" key={index}> + <input + type="radio" + id={`answer${index}`} + value={answer.answerLabel} + onChange={handleChange} + checked={userChoice === answer.answerLabel} + /> + <label htmlFor={`answer${index}`} className="text-16-bold"> + {answer.answerLabel} + </label> + </div> + ))} + </> )} </div> <Button @@ -127,7 +123,7 @@ const QuizQuestionContentCustom = ({ <QuizExplanationModal open={openModal} answerIndex={answerIndex} - question={question} + question={customQuestion} goNext={finishQuiz} handleCloseClick={() => setOpenModal(false)} /> diff --git a/src/models/index.ts b/src/models/index.ts index e4f280922aadaceb2e89fe834fb0a4cc757d3bdc..d59ad6f52a57536fd73d1037425f89d2b7e7bfd1 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -35,4 +35,3 @@ export * from './term.model' export * from './timePeriod.model' export * from './trigger.model' export * from './usageEvent.model' -export * from './userInstanceSettings.model' diff --git a/src/models/userInstanceSettings.model.ts b/src/models/userInstanceSettings.model.ts deleted file mode 100644 index 4202bb58fae14c72c0c7b7068bc306bd66821f26..0000000000000000000000000000000000000000 --- a/src/models/userInstanceSettings.model.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-disable camelcase */ -export interface UserInstanceSettingsAttributes { - auth_mode?: string - auto_update?: boolean - context?: string - email?: string - locale?: string - oidc_id?: string - onboarding_finished?: boolean - public_name: string - tos?: string - tos_latest?: string - uuid?: string -} - -export interface UserInstanceSettings { - data: UserInstanceSettingsAttributes - fetchStatus: string -}