@@ -2,6 +2,10 @@ import { useMemo } from 'react';
22import { useTranslation } from 'react-i18next' ;
33
44const translatedErrorCodes = [
5+ 'NO_CAR_BODY' ,
6+ 'BLURRINESS' ,
7+ 'UNDEREXPOSURE' ,
8+ 'OVEREXPOSURE' ,
59 'TOO_ZOOMED' ,
610 'NOT_ZOOMED_ENOUGH' ,
711 'WRONG_ANGLE' ,
@@ -13,6 +17,19 @@ const translatedErrorCodes = [
1317 'INTERIOR_NOT_SUPPORTED' ,
1418] ;
1519
20+ function getSubtitle ( reasons , t ) {
21+ if ( reasons . length === 0 ) {
22+ return t ( 'uploadCenter.subtitle.unknown' ) ;
23+ }
24+ const translatedReasons = reasons . map ( ( reason ) => {
25+ const key = translatedErrorCodes
26+ . find ( ( errorCode ) => reason . toUpperCase ( ) . startsWith ( errorCode ) ) ;
27+ return key ? t ( `uploadCenter.subtitle.reasons.${ key } ` ) : `[MISSING TRANSLATION : ${ reason } ]` ;
28+ } ) ;
29+ const joinedReasons = translatedReasons . join ( `${ t ( 'uploadCenter.subtitle.reasonsJoin' ) } ` ) ;
30+ return `${ t ( 'uploadCenter.subtitle.reasonsStart' ) } ${ joinedReasons } ` ;
31+ }
32+
1633export default function useSubtitle ( {
1734 isComplianceUnknown,
1835 isComplianceIdle,
@@ -40,31 +57,14 @@ export default function useSubtitle({
4057 const reasons = [ ] ;
4158
4259 if ( badQuality && iqa . reasons ) {
43- iqa . reasons . forEach ( ( reason , index ) => {
44- const errorCode = translatedErrorCodes . find ( ( code ) => reason . startsWith ( code ) ) ;
45- if ( errorCode && errorCode !== 'UNKNOWN_SIGHT' ) {
46- const first = index === 0 ;
47- reasons . push ( first ? t ( `uploadCenter.subtitle.reasons.${ reason } ` )
48- : `${ t ( 'uploadCenter.subtitle.reasonsJoin' ) } ${ t ( `uploadCenter.subtitle.reasons.${ reason } ` ) } ` ) ;
49- }
50- } ) ;
60+ reasons . push ( ...iqa . reasons ) ;
5161 }
5262
5363 if ( badCoverage && carCov . reasons ) {
54- carCov . reasons . forEach ( ( reason , index ) => {
55- const first = index === 0 && ! badQuality ;
56- const errorCode = translatedErrorCodes . find ( ( code ) => reason . startsWith ( code ) ) ;
57- // display all reasons expect `UNKNOWN_SIGHT`
58- if ( errorCode && errorCode !== 'UNKNOWN_SIGHT' ) {
59- reasons . push ( first ? t ( `uploadCenter.subtitle.reasons.${ errorCode } ` )
60- : `${ t ( 'uploadCenter.subtitle.reasonsJoin' ) } ${ t ( `uploadCenter.subtitle.reasons.${ errorCode } ` ) } ` ) ;
61- }
62- } ) ;
64+ reasons . push ( ...carCov . reasons ) ;
6365 }
6466
65- if ( reasons . length > 0 ) {
66- return `${ t ( 'uploadCenter.subtitle.reasonsStart' ) } ${ reasons . join ( ' ' ) } ` ;
67- }
67+ return getSubtitle ( reasons , t ) ;
6868 }
6969
7070 return t ( 'uploadCenter.subtitle.queueBlocked' ) ;
0 commit comments