Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | 2x 1x 2x 4x 4x 4x 1x 4x 1x 4x 1x 1x 4x 4x 4x 2x | import React, { useCallback, useMemo } from 'react';
import ErrorBoundary from 'react-native-error-boundary';
import { SafeAreaView } from 'react-native-safe-area-context';
import Toast from 'react-native-toast-message';
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { SCREENS } from '@repo/constants/screens';
import sentryService from '@repo/services/sentryService';
import { getErrorMessage } from '@repo/utils/error';
import { FallbackError } from '@/components/FallbackError';
import { LoadingSlider } from '@/components/LoadingSlider';
import { useChat } from '@/contexts/ChatContext';
import {
BASE_URL_API,
BASIC_AUTH_PASSWORD,
BASIC_AUTH_USERNAME,
SPACE_URL_API,
} from '@/constants/apis';
import { AppStackScreenProps } from '@/types';
import { getAccessToken } from '@/services/mainHttpClient';
type TimeOffV2RemoteProps = {
onClose: () => void;
onSubmitSuccess?: () => void;
onSubmitError?: (error: unknown) => void;
setFabOffset?: (offset: number) => void;
auth: {
getAccessToken: () => Promise<string | null>;
onUnauthorized?: () => void;
};
env: {
baseApiUrl: string;
spaceApiUrl: string;
basicAuthUsername: string;
basicAuthPassword: string;
};
featureFlags?: Record<string, boolean>;
};
const TimeOffV2Remote = React.lazy(
// @ts-ignore
() => import('timeOff/TimeOffV2'),
) as React.LazyExoticComponent<React.ComponentType<TimeOffV2RemoteProps>>;
type TimeOffV2ScreenProps = AppStackScreenProps<typeof SCREENS.TIME_OFF>;
export const TimeOffV2Screen = ({ navigation }: TimeOffV2ScreenProps) => {
const styles = useStyles();
const { setFabOffset } = useChat();
const handleClose = useCallback(() => {
navigation.goBack();
}, [navigation]);
const handleSubmitSuccess = useCallback(() => {
navigation.navigate(SCREENS.CREATE_REQUEST_SUCCESS);
}, [navigation]);
const handleSubmitError = useCallback((error: unknown) => {
const apiMessage = getErrorMessage(error);
Toast.show({
type: 'error',
text1: 'Failed to create time off request',
...(apiMessage && { text2: apiMessage }),
});
}, []);
const remoteProps = useMemo<TimeOffV2RemoteProps>(
() => ({
onClose: handleClose,
onSubmitSuccess: handleSubmitSuccess,
onSubmitError: handleSubmitError,
setFabOffset,
auth: {
getAccessToken,
},
env: {
baseApiUrl: BASE_URL_API || '',
spaceApiUrl: SPACE_URL_API || BASE_URL_API || '',
basicAuthUsername: BASIC_AUTH_USERNAME || '',
basicAuthPassword: BASIC_AUTH_PASSWORD || '',
},
}),
[handleClose, handleSubmitSuccess, handleSubmitError, setFabOffset],
);
return (
<SafeAreaView style={styles.container}>
<ErrorBoundary
FallbackComponent={FallbackError}
onError={error => sentryService.captureException(error)}
>
<React.Suspense fallback={<LoadingSlider />}>
<TimeOffV2Remote {...remoteProps} />
</React.Suspense>
</ErrorBoundary>
</SafeAreaView>
);
};
const useStyles = makeStyles(theme => ({
container: {
flex: 1,
backgroundColor: theme.colors.background.pageMuted,
},
}));
|