Skip to content

Commit

Permalink
refactor: rename PermissionsRequest{Modal,Wrapper}
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Jul 11, 2024
1 parent 42f093b commit 4f4fd76
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
26 changes: 15 additions & 11 deletions dev-client/src/components/inputs/image/ImagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
ModalHandle,
ModalTrigger,
} from 'terraso-mobile-client/components/modals/Modal';
import {PermissionsRequestModal} from 'terraso-mobile-client/components/modals/PermissionsRequestModal';
import {PermissionsRequestWrapper} from 'terraso-mobile-client/components/modals/PermissionsRequestContext';
import {Column} from 'terraso-mobile-client/components/NativeBaseAdapters';
import {OverlaySheet} from 'terraso-mobile-client/components/sheets/OverlaySheet';

Expand Down Expand Up @@ -100,10 +100,12 @@ export const ImagePicker = ({
return (
<OverlaySheet ref={ref} trigger={children} Closer={null} {...modalProps}>
<Column padding="lg" space="md">
<PermissionsRequestModal
title={t('permissions.camera_title')}
body={t('permissions.camera_body', {feature: featureName})}
usePermissions={useCameraPermissions}
<PermissionsRequestWrapper
requestModalTitle={t('permissions.camera_title')}
requestModalBody={t('permissions.camera_body', {
feature: featureName,
})}
permissionHook={useCameraPermissions}
permissionedAction={onUseCamera}>
{onRequestAction => (
<Button
Expand All @@ -113,11 +115,13 @@ export const ImagePicker = ({
{t('image.use_camera')}
</Button>
)}
</PermissionsRequestModal>
<PermissionsRequestModal
title={t('permissions.gallery_title')}
body={t('permissions.gallery_body', {feature: featureName})}
usePermissions={useMediaLibraryPermissions}
</PermissionsRequestWrapper>
<PermissionsRequestWrapper
requestModalTitle={t('permissions.gallery_title')}
requestModalBody={t('permissions.gallery_body', {
feature: featureName,
})}
permissionHook={useMediaLibraryPermissions}
permissionedAction={onUseMediaLibrary}>
{onRequestAction => (
<Button
Expand All @@ -127,7 +131,7 @@ export const ImagePicker = ({
{t('image.choose_from_gallery')}
</Button>
)}
</PermissionsRequestModal>
</PermissionsRequestWrapper>
<Button
_text={{textTransform: 'uppercase'}}
variant="outline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ import {ModalHandle} from 'terraso-mobile-client/components/modals/Modal';
type PermissionHook = ReturnType<typeof createPermissionHook>;

type Props = {
title: string;
body: string;
usePermissions: PermissionHook;
requestModalTitle: string;
requestModalBody: string;
permissionHook: PermissionHook;
permissionedAction?: () => void;
children: (onOpen: () => void) => React.ReactNode;
};

export const PermissionsRequestModal = ({
title,
body,
usePermissions,
export const PermissionsRequestWrapper = ({
requestModalTitle,
requestModalBody,
permissionHook: usePermissions,
permissionedAction,
children,
}: Props) => {
Expand Down Expand Up @@ -70,8 +70,8 @@ export const PermissionsRequestModal = ({
ref={ref}
isConfirmError={false}
actionName={t('general.open_settings')}
title={title}
body={body}
title={requestModalTitle}
body={requestModalBody}
handleConfirm={Linking.openSettings}
/>
{children(onRequestAction)}
Expand Down
12 changes: 6 additions & 6 deletions dev-client/src/screens/HomeScreen/components/MapSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {Coords} from 'terraso-client-shared/types';

import {IconButton} from 'terraso-mobile-client/components/icons/IconButton';
import {searchBarStyles} from 'terraso-mobile-client/components/ListFilter';
import {PermissionsRequestModal} from 'terraso-mobile-client/components/modals/PermissionsRequestModal';
import {PermissionsRequestWrapper} from 'terraso-mobile-client/components/modals/PermissionsRequestContext';
import {
Box,
Column,
Expand Down Expand Up @@ -214,10 +214,10 @@ export default function MapSearch({zoomTo, zoomToUser, toggleMapLayer}: Props) {
padding={2}
onPress={toggleMapLayer}
/>
<PermissionsRequestModal
title={t('permissions.location_title')}
body={t('permissions.location_body')}
usePermissions={useForegroundPermissions}
<PermissionsRequestWrapper
requestModalTitle={t('permissions.location_title')}
requestModalBody={t('permissions.location_body')}
permissionHook={useForegroundPermissions}
permissionedAction={zoomToUser}>
{onRequest => (
<IconButton
Expand All @@ -229,7 +229,7 @@ export default function MapSearch({zoomTo, zoomToUser, toggleMapLayer}: Props) {
onPress={onRequest}
/>
)}
</PermissionsRequestModal>
</PermissionsRequestWrapper>
</Column>
</Row>
</Box>
Expand Down
12 changes: 6 additions & 6 deletions dev-client/src/screens/SlopeScreen/SlopeMeterScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {updateSoilData} from 'terraso-client-shared/soilId/soilIdSlice';

import {BigCloseButton} from 'terraso-mobile-client/components/buttons/BigCloseButton';
import {Icon} from 'terraso-mobile-client/components/icons/Icon';
import {PermissionsRequestModal} from 'terraso-mobile-client/components/modals/PermissionsRequestModal';
import {PermissionsRequestWrapper} from 'terraso-mobile-client/components/modals/PermissionsRequestContext';
import {
Box,
Column,
Expand Down Expand Up @@ -100,18 +100,18 @@ export const SlopeMeterScreen = ({siteId}: {siteId: string}) => {
</Column>
</CameraView>
) : (
<PermissionsRequestModal
title={t('permissions.camera_title')}
body={t('permissions.camera_body', {
<PermissionsRequestWrapper
requestModalTitle={t('permissions.camera_title')}
requestModalBody={t('permissions.camera_body', {
feature: t('slope.steepness.slope_meter'),
})}
usePermissions={useCameraPermissions}>
permissionHook={useCameraPermissions}>
{onRequest => (
<Button size="lg" onPress={onRequest}>
{t('slope.steepness.camera_grant')}
</Button>
)}
</PermissionsRequestModal>
</PermissionsRequestWrapper>
)}
</Box>
<Column alignItems="center">
Expand Down

0 comments on commit 4f4fd76

Please sign in to comment.