Skip to content

Commit

Permalink
Added error display to cheatcodes if input is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
cgerrard-pass committed Feb 9, 2025
1 parent 67e0ded commit cb890da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import React from 'react'
import React, { useEffect, useState } from 'react'

import { CheatcodesTemplateScreen } from 'cheatcodes/components/CheatcodesTemplateScreen'
import { RemoteBanner } from 'features/remoteBanner/components/RemoteBanner'
import { Spacer } from 'ui/theme'
import { remoteBannerSchema } from 'features/remoteBanner/components/remoteBannerSchema'
import { useFeatureFlagOptions } from 'libs/firebase/firestore/featureFlags/useFeatureFlagOptions'
import { RemoteStoreFeatureFlags } from 'libs/firebase/firestore/types'
import { ErrorBanner } from 'ui/components/banners/ErrorBanner'
import { ViewGap } from 'ui/components/ViewGap/ViewGap'
import { getSpacing } from 'ui/theme'

export const CheatcodesScreenRemoteBanner = () => {
const { options } = useFeatureFlagOptions(RemoteStoreFeatureFlags.SHOW_REMOTE_BANNER)
const [error, setError] = useState('')

useEffect(() => {
try {
remoteBannerSchema.validateSync(options)
} catch (error) {
setError(String(error))
}
}, [options])

return (
<CheatcodesTemplateScreen title="RemoteBanner 🆒" flexDirection="column">
<Spacer.Column numberOfSpaces={3} />
<RemoteBanner />
<ViewGap gap={getSpacing(3)}>
<RemoteBanner />
{error ? (
<ErrorBanner
message={`La bannière ne s‘affichera pas à cause de l’erreur suivante:\n${error}`}
/>
) : null}
</ViewGap>
</CheatcodesTemplateScreen>
)
}
2 changes: 1 addition & 1 deletion src/features/remoteBanner/components/remoteBannerSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InferType, object, string } from 'yup'

const remoteBannerSchema = object({
export const remoteBannerSchema = object({
title: string().required(),
subtitleWeb: string().nullable(),
subtitleMobile: string().nullable(),
Expand Down

0 comments on commit cb890da

Please sign in to comment.