Skip to content

Commit

Permalink
Fix : Inspection report handle tasks in error
Browse files Browse the repository at this point in the history
  • Loading branch information
souyahia-monk committed Nov 3, 2023
1 parent 9ee5b41 commit ce14456
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const styles = StyleSheet.create({
},
tabDesktopInnerContainer: {
width: '50%',
paddingHorizontal: 15
paddingHorizontal: 15,
},
text: {
color: '#fafafa',
Expand Down Expand Up @@ -111,7 +111,7 @@ const styles = StyleSheet.create({
galleryWrapper: {
maxHeight: '39vh',
overflowY: 'auto',
paddingBottom: 15
paddingBottom: 15,
},
});

Expand Down Expand Up @@ -144,6 +144,7 @@ export default function DamageReport({
isError,
retry,
isInspectionReady,
inspectionErrors,
vinNumber,
pictures,
damages,
Expand Down Expand Up @@ -213,15 +214,15 @@ export default function DamageReport({
if (pdfStatus === PdfStatus.ERROR) {
setIsEditable(true);
}
}, [pdfStatus])
}, [pdfStatus]);

useEffect(() => {
if (isPopUpVisible) {
setShowPictures(false);
} else {
setShowPictures(true);
}
}, [isPopUpVisible])
}, [isPopUpVisible]);

return (
<View style={[styles.container]}>
Expand All @@ -231,8 +232,20 @@ export default function DamageReport({
{
isDesktopMode && (
<>
<Text style={[styles.text, styles.subTitle]}>{t('damageReport.inspection')} : {inspectionId}</Text>
<Text style={[styles.text, styles.subTitle]}>{t('damageReport.vinNumber')} : {vinNumber}</Text>
<Text style={[styles.text, styles.subTitle]}>
{t('damageReport.inspection')}
{' '}
:
{' '}
{inspectionId}
</Text>
<Text style={[styles.text, styles.subTitle]}>
{t('damageReport.vinNumber')}
{' '}
:
{' '}
{vinNumber}
</Text>
</>
)
}
Expand All @@ -259,10 +272,29 @@ export default function DamageReport({
</TouchableOpacity>
</View>
)}
{!isLoading && !isError && (
{!isLoading && inspectionErrors.isInError && (
<View style={[styles.notReadyContainer]}>
<Text style={[styles.notReadyMessage]}>{t('damageReport.inspectionInError.message')}</Text>
<Text
style={[styles.notReadyMessage, { fontFamily: 'monospace' }]}
>
{`${t('damageReport.inspectionInError.id')} : ${inspectionId}`}
</Text>
<Text
style={[styles.notReadyMessage, { fontFamily: 'monospace' }]}
>
{`${t('damageReport.inspectionInError.tasks')} : ${inspectionErrors.tasks.join(', ')}`}
</Text>
<TouchableOpacity style={[styles.retryButton]} onPress={onStartNewInspection}>
<Text style={[styles.retryTxt]}>{t('damageReport.inspectionInError.startNewInspection')}</Text>
</TouchableOpacity>
</View>
)}
{!isLoading && !isError && !inspectionErrors.isInError && (
<>
{
!isDesktopMode &&
!isDesktopMode
&& (
<View style={[styles.tabGroup]}>
<TabGroup>
<TabButton
Expand All @@ -281,6 +313,7 @@ export default function DamageReport({
/>
</TabGroup>
</View>
)
}
<View style={[styles.tabContent, isDesktopMode && styles.tabDesktopContent]}>
<View style={[isDesktopMode && styles.tabDesktopInnerContainer]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function useFetchInspection({
processInspection,
resetState,
isInspectionReady,
inspectionErrors,
vinNumber,
pictures,
damages,
Expand Down Expand Up @@ -60,6 +61,7 @@ export default function useFetchInspection({
isError,
retry,
isInspectionReady,
inspectionErrors,
vinNumber,
pictures,
damages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import monk from '@monkvision/corejs';

import { RepairOperation, Severity } from '../../../resources';

const REQUIRED_INSPECTION_TASKS = [
'damage_detection',
'wheel_analysis',
'images_ocr',
'repair_estimate',
'pricing',
'dashboard_ocr',
];

function getRepairOperation(repairType) {
switch (repairType) {
case true:
Expand Down Expand Up @@ -40,7 +49,7 @@ function getRenderedOutputImages(image) {
isRendered: true,
label: image.additional_data?.label ?? undefined,
url: damagedImage.path,
}
};
}

function getPictures(inspection) {
Expand Down Expand Up @@ -80,6 +89,7 @@ function getDamages(inspection) {

export default function useProcessInspection() {
const [isInspectionReady, setIsInspectionReady] = useState(false);
const [inspectionErrors, setInspectionErrors] = useState({ isInError: false, tasks: [] });
const [vinNumber, setVinNumber] = useState('');
const [pictures, setPictures] = useState([]);
const [damages, setDamages] = useState([]);
Expand All @@ -91,11 +101,17 @@ export default function useProcessInspection() {
}, []);

const processInspection = useCallback((axiosResponse) => {
const tasks = axiosResponse.data.tasks
.filter((task) => REQUIRED_INSPECTION_TASKS.includes(task.name));
setIsInspectionReady(
axiosResponse.data.tasks
.filter((task) => (task.name !== 'inspection_pdf'))
.every((task) => (task.status === monk.types.InspectionStatus.DONE)),
tasks.every((task) => (task.status === monk.types.InspectionStatus.DONE)),
);
const tasksInError = tasks
.filter((task) => (task.status === monk.types.InspectionStatus.ERROR));
setInspectionErrors({
isInError: tasksInError.length > 0,
tasks: tasksInError,
});
setPictures(getPictures(axiosResponse.data));
setDamages(getDamages(axiosResponse.data));
setVinNumber(axiosResponse.data?.vehicle?.vin);
Expand All @@ -105,6 +121,7 @@ export default function useProcessInspection() {
processInspection,
resetState,
isInspectionReady,
inspectionErrors,
vinNumber,
pictures,
damages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { I18nextProvider } from 'react-i18next';

import i18n from '../../i18n';
import DamageReport from './DamageReport';
import { CurrencyProvider } from './../../hooks';
import { CurrencyProvider } from '../../hooks';

function DamageReportHOC(props) {
return (
Expand Down
6 changes: 6 additions & 0 deletions packages/inspection-report/src/i18n/resources/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const en = {
message: 'An unexpected error occurred while fetching the inspection results.',
retry: 'Retry',
},
inspectionInError: {
message: 'Sorry, an unexpected error occurred during the inspection. Please contact the support with the following information :',
id: 'Inspection ID',
tasks: 'Failed tasks',
startNewInspection: 'New Inspection',
},
loading: 'Fetching inspection results...',
notReady: 'Inspection still in progress...',
validate: 'Validate',
Expand Down
6 changes: 6 additions & 0 deletions packages/inspection-report/src/i18n/resources/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const fr = {
message: 'Une erreur inattendue est survenue lors de la récupération des résultats de l\'inspection.',
retry: 'Réessayer',
},
inspectionInError: {
message: 'Désolé, une erreur inattendue est survenue lors de l\'inspection. Veuillez contacter le support avec les informations suivantes :',
id: 'Identifiant de l\'inspection',
tasks: 'Tâches en erreur',
startNewInspection: 'Nouvelle Inspection',
},
loading: 'Récupération des résultats...',
notReady: 'Inspection en cours...',
validate: 'Valider',
Expand Down

0 comments on commit ce14456

Please sign in to comment.