Skip to content

Commit

Permalink
fix an issue to add & show labels for added damaged parts in Damage-R…
Browse files Browse the repository at this point in the history
…eports photoes section (#555)
  • Loading branch information
rohitsharma120582 authored Aug 24, 2023
1 parent 0f7ac7f commit c468e53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/camera/src/components/Capture/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const Capture = forwardRef(({
endTour,
};
const startUploadAsync = useStartUploadAsync(startUploadAsyncParams);
const uploadAdditionalDamage = useUploadAdditionalDamage({ inspectionId });
const uploadAdditionalDamage = useUploadAdditionalDamage({ inspectionId, addDamageParts });

const [goPrevSight, goNextSight] = useNavigationBetweenSights({ sights });

Expand Down
19 changes: 15 additions & 4 deletions packages/camera/src/components/Capture/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { manipulateAsync, SaveFormat } from 'expo-image-manipulator';

import { useCallback, useEffect, useMemo, useState } from 'react';
import { Platform } from 'react-native';
import { useTranslation } from 'react-i18next';
import Actions from '../../actions';
import Constants from '../../const';
import log from '../../utils/log';
Expand Down Expand Up @@ -304,9 +305,9 @@ export function useStartUploadAsync({
}, [uploads, inspectionId, sights.state, mapTasksToSights, task, onFinish, endTour]);
}

export function useUploadAdditionalDamage({
inspectionId,
}) {
export function useUploadAdditionalDamage({ inspectionId, addDamageParts }) {
const { t, i18n } = useTranslation();

return useCallback(async ({ picture, parts }) => {
if (!inspectionId) {
throw Error(`Please provide a valid "inspectionId". Got ${inspectionId}.`);
Expand All @@ -322,6 +323,15 @@ export function useUploadAdditionalDamage({
filename,
};

const part = addDamageParts[0];
const resources = Object.keys(i18n.options.resources);
const metadata = {
category: 'exterior',
label: resources.reduce((accumulator, lng) => {
accumulator[lng] = t(`partSelector.parts.${part}`, { lng });
return accumulator;
}, {}),
};
const json = JSON.stringify({
acquisition: {
strategy: 'upload_multipart_form_keys',
Expand All @@ -336,6 +346,7 @@ export function useUploadAdditionalDamage({
tasks: ['damage_detection'],
image_type: 'close_up',
additional_data: {
...metadata,
overlay: undefined,
createdAt: new Date(),
},
Expand Down Expand Up @@ -375,7 +386,7 @@ export function useUploadAdditionalDamage({

throw err;
}
}, [inspectionId]);
}, [inspectionId, addDamageParts]);
}

/**
Expand Down

0 comments on commit c468e53

Please sign in to comment.