All files / apps/host/src/screens/NewRequest index.tsx

100% Statements 19/19
100% Branches 0/0
100% Functions 9/9
100% Lines 17/17

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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168                                                                2x 15x 2x     15x                           2x 3x 3x   3x 3x                                                           3x   2x         15x   3x   15x         3x       1x                                           3x                                                                              
import { memo, useCallback, useMemo } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
 
import { FlashList } from '@shopify/flash-list';
 
import { ScreenLayout } from '@repo/ui/components/ScreenLayout';
import { BrandIcon } from '@repo/ui/icons/Brand';
import { BuildingIcon } from '@repo/ui/icons/Building';
import { CalendarIcon } from '@repo/ui/icons/Calendar';
import { ChevronLeftIcon } from '@repo/ui/icons/ChevronLeft';
import { ExchangeIcon } from '@repo/ui/icons/Exchange';
import { FoodPlateIcon } from '@repo/ui/icons/FoodPlate';
import { GearIcon } from '@repo/ui/icons/Gear';
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { useTheme } from '@repo/ui/themes/ThemeContext';
 
import { SCREENS } from '@repo/constants/screens';
 
import type { AppStackParamList, AppStackScreenProps } from '@/types/navigation';
 
type NewRequestScreenProps = AppStackScreenProps<typeof SCREENS.NEW_REQUEST>;
 
interface MenuItemProps {
  item: {
    title: string;
    icon: React.ReactNode;
    path: Exclude<keyof AppStackParamList, typeof SCREENS.REQUEST_DETAIL>;
  };
  onPress: (path: Exclude<keyof AppStackParamList, typeof SCREENS.REQUEST_DETAIL>) => void;
  styles: any;
}
 
const MenuItem = memo(function MenuItem({ item, onPress, styles }: MenuItemProps) {
  const handlePress = useCallback(() => {
    onPress(item.path);
  }, [item.path, onPress]);
 
  return (
    <TouchableOpacity
      style={styles.item}
      onPress={handlePress}
      accessibilityRole="button"
      accessibilityLabel={item.title}
      accessibilityHint={`Navigate to ${item.title}`}
    >
      {item.icon}
      <Text style={styles.itemTitle}>{item.title}</Text>
    </TouchableOpacity>
  );
});
 
export const NewRequestScreen = ({ navigation }: NewRequestScreenProps) => {
  const { theme } = useTheme();
  const styles = useStyles();
 
  const MENU_ITEMS = useMemo(
    () => [
      {
        title: 'Time Off',
        icon: <CalendarIcon color={theme.colors.icon.active} />,
        path: SCREENS.TIME_OFF,
      },
      {
        title: 'Book a Room',
        icon: <BuildingIcon color={theme.colors.icon.active} />,
        path: SCREENS.BOOK_ROOM,
      },
      {
        title: 'Reallocation',
        icon: <ExchangeIcon color={theme.colors.icon.active} />,
        path: SCREENS.REALLOCATION,
      },
      {
        title: 'Maintenance',
        icon: <GearIcon color={theme.colors.icon.active} />,
        path: SCREENS.MAINTENANCE,
      },
      {
        title: 'Meal Reservation',
        icon: <FoodPlateIcon color={theme.colors.icon.active} />,
        path: SCREENS.MEAL_RESERVATION,
      },
    ],
    [theme.colors.icon.active],
  );
 
  const handlePress = useCallback(
    (screen: Exclude<keyof AppStackParamList, typeof SCREENS.REQUEST_DETAIL>) => {
      navigation.navigate(screen);
    },
    [navigation],
  );
 
  const keyExtractor = useCallback((item: (typeof MENU_ITEMS)[0]) => item.title, []);
 
  const renderItem = useCallback(
    ({ item }: { item: (typeof MENU_ITEMS)[0] }) => (
      <MenuItem item={item} onPress={handlePress} styles={styles} />
    ),
    [handlePress, styles],
  );
 
  return (
    <ScreenLayout style={styles.container}>
      <View style={styles.header}>
        <TouchableOpacity
          onPress={() => navigation.goBack()}
          accessibilityRole="button"
          accessibilityLabel="Go back"
        >
          <ChevronLeftIcon />
        </TouchableOpacity>
        <BrandIcon />
        <View style={styles.spacer} />
      </View>
 
      <FlashList
        data={MENU_ITEMS}
        keyExtractor={keyExtractor}
        contentContainerStyle={styles.list}
        renderItem={renderItem}
        accessibilityRole="list"
        accessibilityLabel="Request types"
      />
    </ScreenLayout>
  );
};
 
const useStyles = makeStyles(theme => ({
  container: {
    padding: theme.metrics.spacing[4],
    gap: theme.metrics.spacing[12.5],
  },
  header: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
  },
  item: {
    flexDirection: 'row',
    alignItems: 'center',
    padding: theme.metrics.spacing[5],
    borderWidth: theme.metrics.borderWidth.default,
    borderColor: theme.colors.border.default,
    borderRadius: theme.metrics.borderRadius[3],
    backgroundColor: theme.colors.background.default,
    gap: theme.metrics.spacing[3],
    marginBottom: theme.metrics.spacing[1],
  },
  list: {
    flex: 1,
    paddingBottom: theme.metrics.spacing[4],
  },
  itemTitle: {
    fontSize: theme.metrics.textSize[16],
    fontWeight: theme.metrics.fontWeight.semiBold,
    color: theme.colors.text.primary,
  },
  itemDescription: {
    color: theme.colors.text.secondary,
  },
  spacer: {
    width: theme.metrics.iconSize[24],
  },
}));
 
export default NewRequestScreen;