Skip to content

Commit

Permalink
Added disable option for AddDamage feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dlymonk committed Apr 30, 2024
1 parent 41177b9 commit 454794c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function PhotoCapturePage() {
enforceOrientation={DeviceOrientation.LANDSCAPE}
allowSkipRetake={false}
useLiveCompliance={true}
disableAddDamage={true}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export interface PhotoCaptureProps
* @default false
*/
allowSkipRetake?: boolean;
/**
* Boolean indicating whether the Add Damage feature is disabled. If disabled, the `Add Damage` button will be hidden.
*
* @default false
*/
disableAddDamage?: boolean;
}

enum PhotoCaptureScreen {
Expand All @@ -109,6 +115,7 @@ export function PhotoCapture({
enableCompliance = true,
useLiveCompliance = false,
allowSkipRetake = false,
disableAddDamage = false,
complianceIssues,
lang,
enforceOrientation,
Expand Down Expand Up @@ -204,6 +211,7 @@ export function PhotoCapture({
inspectionId,
showCloseButton,
images,
disableAddDamage,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export interface PhotoCaptureHUDProps extends CameraHUDProps {
* The current images taken by the user (ignoring retaken pictures etc.).
*/
images: Image[];
/**
* Boolean indicating whether the Add Damage feature is disabled. If disabled, the `Add Damage` button will be hidden.
*
* @default false
*/
disableAddDamage?: boolean;
}

/**
Expand All @@ -102,6 +108,7 @@ export function PhotoCaptureHUD({
handle,
cameraPreview,
images,
disableAddDamage,
}: PhotoCaptureHUDProps) {
const { t } = useTranslation();
const [showCloseModal, setShowCloseModal] = useState(false);
Expand Down Expand Up @@ -135,6 +142,7 @@ export function PhotoCaptureHUD({
error={loading.error ?? handle.error}
streamDimensions={handle.dimensions}
images={images}
disableAddDamage={disableAddDamage}
/>
</div>
<PhotoCaptureHUDButtons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export interface PhotoCaptureHUDPreviewProps {
* The current images taken by the user (ignoring retaken pictures etc.).
*/
images: Image[];
/**
* Boolean indicating whether the Add Damage feature is disabled. If disabled, the `Add Damage` button will be hidden.
*
* @default false
*/
disableAddDamage?: boolean;
}

/**
Expand All @@ -71,6 +77,7 @@ export function PhotoCaptureHUDPreview(params: PhotoCaptureHUDPreviewProps) {
onAddDamage={params.onAddDamage}
streamDimensions={params.streamDimensions}
images={params.images}
disableAddDamage={params.disableAddDamage}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ export interface AddDamageButtonProps {
* Callback called when the user presses the button.
*/
onAddDamage?: () => void;
/**
* Boolean indicating whether the Add Damage feature is disabled. If disabled, the `Add Damage` button will be hidden.
*
* @default false
*/
disableAddDamage?: boolean;
}

/**
* Custom button displayed in the PhotoCapture Camera HUD that allows user to enter add damage mode.
*/
export function AddDamageButton({ onAddDamage }: AddDamageButtonProps) {
export function AddDamageButton({ onAddDamage, disableAddDamage }: AddDamageButtonProps) {
const { t } = useTranslation();
const primaryColor = usePhotoCaptureHUDButtonBackground();

return (
<Button
icon='add'
style={{ visibility: disableAddDamage ? 'hidden' : 'visible' }}
disabled={disableAddDamage}
onClick={onAddDamage}
data-testid='monk-test-btn'
primaryColor={primaryColor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export interface PhotoCaptureHUDSightPreviewProps {
* The current images taken by the user (ignoring retaken pictures etc.).
*/
images: Image[];
/**
* Boolean indicating whether the Add Damage feature is disabled. If disabled, the `Add Damage` button will be hidden.
*
* @default false
*/
disableAddDamage?: boolean;
}

/**
Expand All @@ -53,6 +59,7 @@ export function PhotoCaptureHUDPreviewSight({
sightsTaken,
streamDimensions,
images,
disableAddDamage,
}: PhotoCaptureHUDSightPreviewProps) {
const style = usePhotoCaptureHUDSightPreviewStyle();
const aspectRatio = `${streamDimensions?.width}/${streamDimensions?.height}`;
Expand All @@ -68,7 +75,7 @@ export function PhotoCaptureHUDPreviewSight({
totalSights={sights.length}
sightsTaken={sightsTaken.length}
/>
<AddDamageButton onAddDamage={onAddDamage} />
<AddDamageButton onAddDamage={onAddDamage} disableAddDamage={disableAddDamage} />
</div>
<SightSlider
sights={sights}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const styles: Styles = {
scrollbarWidth: 'none',
maxWidth: '60vw',
zIndex: '9',
bottom: '0',
bottom: '10px',
right: `${PHOTO_CAPTURE_HUD_BUTTONS_BAR_WIDTH * 2}px`,
left: '0',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function createProps(): PhotoCaptureProps {
showCloseButton: true,
lang: 'de',
allowSkipRetake: true,
disableAddDamage: false,
};
}

Expand Down Expand Up @@ -233,6 +234,7 @@ describe('PhotoCapture component', () => {
showCloseButton: props.showCloseButton,
onOpenGallery: expect.any(Function),
images,
disableAddDamage: props.disableAddDamage,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@ describe('AddDamageButton component', () => {

unmount();
});

it('should be disable and not visible when disableAddDamage is true', () => {
const onAddDamage = jest.fn();
const { unmount } = render(
<AddDamageButton onAddDamage={onAddDamage} disableAddDamage={true} />,
);

expectPropsOnChildMock(Button, { style: { visibility: 'hidden' }, disabled: true });

unmount();
});
});

0 comments on commit 454794c

Please sign in to comment.