All files / apps/roomBooking/src/screens/ChooseReason index.tsx

100% Statements 12/12
100% Branches 4/4
100% Functions 3/3
100% Lines 11/11

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                                        1x 7x 7x   7x                           7x   7x 2x 1x 1x       7x                                                                                     7x                                      
import React, { memo, useCallback } from 'react';
import { KeyboardAwareScrollView } from 'react-native-keyboard-controller';
import { Pressable, TextInput, View } from 'react-native';
 
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
 
import { QuickSelect } from '@repo/ui/components/QuickSelect';
import { MoreIcon } from '@repo/ui/icons/More';
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { useTheme } from '@repo/ui/themes/ThemeContext';
import { textStyles } from '@repo/ui/themes/typography';
 
import {
  RoomBookingStackParamList,
  RoomBookingStep,
} from '../RoomBooking/types';
 
import { quickReasonOptions, useChooseReason } from './hooks';
 
const ChooseReason = () => {
  const styles = useStyles();
  const { theme } = useTheme();
  const navigation =
    useNavigation<NativeStackNavigationProp<RoomBookingStackParamList>>();
  const {
    state: {
      isOpenReasonInput,
      quickReason,
      reasonInputValue,
      canSubmitReasonInput,
    },
    actions: {
      setReasonInputValue,
      openReasonInput,
      handleChangeQuickReason,
      handleSubmitTextInput,
    },
  } = useChooseReason();
 
  const handleSubmitEditing = useCallback(() => {
    if (canSubmitReasonInput) {
      handleSubmitTextInput();
      navigation.navigate(RoomBookingStep.PREVIEW);
    }
  }, [canSubmitReasonInput, handleSubmitTextInput, navigation]);
 
  return (
    <>
      {isOpenReasonInput ? (
        <KeyboardAwareScrollView keyboardShouldPersistTaps="handled">
          <TextInput
            autoFocus
            style={styles.input}
            value={reasonInputValue}
            submitBehavior="submit"
            returnKeyType="done"
            enablesReturnKeyAutomatically
            onChangeText={setReasonInputValue}
            multiline
            testID="reason-input"
            onSubmitEditing={handleSubmitEditing}
            accessibilityLabel="Reason for relocation"
          />
        </KeyboardAwareScrollView>
      ) : (
        <View style={styles.container}>
          <QuickSelect
            options={quickReasonOptions}
            value={quickReason}
            onChange={handleChangeQuickReason}
            testID="choose-reason-quick-select"
          />
          <Pressable
            accessibilityRole="button"
            accessibilityLabel="Open reason input"
            testID="more-btn"
            style={styles.moreIcon}
            onPress={openReasonInput}
          >
            <MoreIcon color={theme.colors.icon.brand} />
          </Pressable>
        </View>
      )}
    </>
  );
};
 
export default memo(ChooseReason);
 
const useStyles = makeStyles(theme => ({
  container: {
    flex: 1,
    paddingHorizontal: theme.metrics.spacing[4],
    gap: theme.metrics.spacing[6],
    backgroundColor: theme.colors.background.pageMuted,
  },
  moreIcon: {
    borderRadius: theme.metrics.borderRadius.pill,
    width: theme.metrics.spacing[15],
    height: theme.metrics.spacing[15],
  },
  input: {
    padding: theme.metrics.spacing[4],
    paddingTop: -theme.metrics.spacing[4],
    ...textStyles.content.regular,
    color: theme.colors.text.onBehalf,
  },
}));