All files / apps/host/src/components/RequestCardDetailSkeleton index.tsx

100% Statements 30/30
100% Branches 16/16
100% Functions 8/8
100% Lines 29/29

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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327                                                3x 107x 107x   107x 107x     107x 107x 107x 107x     107x                                                 3x                 3x                 8x 8x 8x   8x 7x   1x                                         1x                                                     1x                                             4x                             8x 7x                                                                                   8x 1x                                                           8x 2x               6x     8x                                                                                                                                    
import React from 'react';
import Animated, {
  interpolate,
  useAnimatedStyle,
  useSharedValue,
  withRepeat,
  withTiming,
} from 'react-native-reanimated';
import { DimensionValue, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
 
import { useNavigation } from '@react-navigation/native';
 
import { HeaderRequest } from '@repo/ui/components/HeaderRequest';
import { ScreenLayout } from '@repo/ui/components/ScreenLayout';
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { useTheme } from '@repo/ui/themes/ThemeContext';
 
interface SkeletonProps {
  width: DimensionValue;
  height: DimensionValue;
  radius?: number;
  style?: StyleProp<ViewStyle>;
}
 
const Skeleton = ({ width, height, radius = 6, style }: SkeletonProps) => {
  const { theme } = useTheme();
  const progress = useSharedValue(0);
 
  React.useEffect(() => {
    progress.value = withRepeat(withTiming(1, { duration: 1200 }), -1, false);
  }, [progress]);
 
  const animatedStyle = useAnimatedStyle(() => {
    const translationWidth = typeof width === 'number' ? width : 300; // Fallback for percentage width animation
    const translateX = interpolate(progress.value, [0, 1], [-translationWidth, translationWidth]);
    return { transform: [{ translateX }] };
  });
 
  return (
    <View
      className={`overflow-hidden`}
      style={[
        {
          width,
          height,
          borderRadius: radius,
          backgroundColor: theme.colors.skeleton.default,
        },
        style,
      ]}
    >
      <Animated.View
        className={`opacity-50`}
        style={[
          localStyles.fullSize,
          { backgroundColor: theme.colors.skeleton.active },
          animatedStyle,
        ]}
      />
    </View>
  );
};
 
const localStyles = StyleSheet.create({
  fullSize: {
    width: '100%',
    height: '100%',
  },
});
 
import { RequestCategory } from '@/types/request';
 
export const RequestCardDetailSkeleton = ({
  isFullScreen = false,
  type = 'detail',
  category = RequestCategory.MAINTENANCE,
}: {
  isFullScreen?: boolean;
  type?: 'detail' | 'card';
  category?: RequestCategory;
}) => {
  const styles = useStyles();
  const { theme } = useTheme();
  const navigation = useNavigation();
 
  const renderInfoList = () => {
    switch (category) {
      case RequestCategory.TIME_OFF:
        return (
          <View className="px-4 gap-4">
            <View className="flex-row gap-20">
              <View className="gap-2 flex-1">
                <Skeleton width={60} height={16} />
                <Skeleton width={'100%'} height={20} />
                <Skeleton width={100} height={20} />
              </View>
              <View className="gap-2 flex-1">
                <Skeleton width={60} height={16} />
                <Skeleton width={'100%'} height={20} />
                <Skeleton width={100} height={20} />
              </View>
            </View>
            <View className="gap-2">
              <Skeleton width={60} height={16} />
              <Skeleton width={40} height={20} />
            </View>
          </View>
        );
      case RequestCategory.BOOK_ROOM:
        return (
          <View className="px-4 gap-4">
            <View className="gap-2">
              <Skeleton width={60} height={16} />
              <Skeleton width={120} height={20} />
            </View>
            <View className="gap-2">
              <Skeleton width={60} height={16} />
              <Skeleton width={180} height={20} />
            </View>
            <View className="flex-row gap-20">
              <View className="gap-2 flex-1">
                <Skeleton width={60} height={16} />
                <Skeleton width={'100%'} height={20} />
              </View>
              <View className="gap-2 flex-1">
                <Skeleton width={60} height={16} />
                <Skeleton width={'100%'} height={20} />
              </View>
            </View>
            <View className="gap-2">
              <Skeleton width={60} height={16} />
              <Skeleton width={40} height={20} />
            </View>
          </View>
        );
      case RequestCategory.REALLOCATION:
        return (
          <View className="px-4 gap-6">
            <View className="flex-row gap-20">
              <View className="gap-2 flex-1">
                <Skeleton width={60} height={16} />
                <Skeleton width={'100%'} height={20} />
              </View>
              <View className="gap-2 flex-1">
                <Skeleton width={60} height={16} />
                <Skeleton width={'100%'} height={20} />
              </View>
            </View>
            <View className="gap-2">
              <Skeleton width={60} height={16} />
              <Skeleton width={'100%'} height={20} />
            </View>
            <View className="gap-2">
              <Skeleton width={60} height={16} />
              <Skeleton width={100} height={20} />
            </View>
          </View>
        );
      default: // MAINTENANCE or fallback
        return (
          <View className="px-4 gap-6">
            <View className="gap-2">
              <Skeleton width={60} height={16} />
              <Skeleton width={200} height={20} />
            </View>
            <View className="gap-2">
              <Skeleton width={60} height={16} />
              <Skeleton width={'100%'} height={20} />
            </View>
          </View>
        );
    }
  };
 
  const renderDetailSkeleton = () => {
    return (
      <View style={styles.container}>
        {/* Title & Status */}
        <View
          className="flex-row justify-between mb-4"
          style={{ paddingHorizontal: theme.metrics.spacing[4] }}
        >
          <Skeleton width={160} height={28} />
          <Skeleton width={100} height={28} />
        </View>
 
        <View className="mx-4">
          {/* Requester section */}
          <View className="flex-row items-center justify-between px-4 mb-10">
            <View className="flex-row items-center gap-4">
              <Skeleton width={40} height={40} radius={999} />
              <Skeleton width={180} height={24} />
            </View>
            {category === RequestCategory.TIME_OFF && (
              <Skeleton width={40} height={40} radius={22} />
            )}
          </View>
 
          {/* Info list section */}
          {renderInfoList()}
 
          {/* History Header */}
          <View className="px-4 mt-6 gap-4">
            <Skeleton width={80} height={16} />
            <View className="flex-row items-center gap-4">
              <Skeleton width={56} height={56} radius={999} />
              <View className="gap-2 flex-1">
                <Skeleton width={'90%'} height={20} />
                <Skeleton width={140} height={14} />
              </View>
            </View>
          </View>
        </View>
      </View>
    );
  };
 
  const renderCardSkeleton = () => {
    return (
      <View style={styles.cardContainer}>
        {/* Header Row: Requester Info */}
        <View style={styles.cardHeaderRow}>
          <View style={styles.userInfo}>
            <Skeleton width={60} height={60} radius={30} />
            <Skeleton width={150} height={24} />
          </View>
          {/* Optional Badge placeholder */}
          <Skeleton width={60} height={60} radius={30} />
        </View>
 
        {/* Info Section */}
        <View style={styles.cardInfoContainer}>
          <View style={styles.badgeRow}>
            <Skeleton width={140} height={36} radius={4} />
            <Skeleton width={100} height={36} radius={4} />
          </View>
        </View>
 
        {/* Reason Section */}
        <View style={styles.cardReasonSection}>
          <Skeleton width={80} height={20} style={styles.marginBottom8} />
          <Skeleton width={'100%'} height={16} />
          <Skeleton width={'80%'} height={16} style={styles.marginTop4} />
        </View>
      </View>
    );
  };
 
  if (isFullScreen) {
    return (
      <ScreenLayout>
        <HeaderRequest title="Request Detail" onBack={navigation.goBack} />
        {renderDetailSkeleton()}
      </ScreenLayout>
    );
  }
 
  return type === 'card' ? renderCardSkeleton() : renderDetailSkeleton();
};
 
const useStyles = makeStyles(theme => ({
  container: {
    paddingTop: theme.metrics.spacing[4],
    marginHorizontal: theme.metrics.spacing[4],
    gap: theme.metrics.spacing[4],
    borderRadius: theme.metrics.borderRadius[2],
    backgroundColor: theme.colors.background.secondary,
    shadowColor: theme.colors.shadow.black,
    shadowOffset: { width: 0, height: theme.metrics.spacing[3] },
    shadowOpacity: 0.15,
    shadowRadius: 16,
    elevation: 12,
    flex: 1,
  },
  cardContainer: {
    padding: theme.metrics.spacing[4],
    gap: theme.metrics.spacing[6],
    borderRadius: theme.metrics.borderRadius[7.5],
    backgroundColor: theme.colors.background.secondary,
    shadowColor: theme.colors.shadow.black,
    shadowOffset: { width: 0, height: theme.metrics.spacing[0.5] },
    shadowOpacity: 0.1,
    shadowRadius: 4,
    elevation: 10,
    flex: 1,
  },
  headerRow: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    paddingHorizontal: theme.metrics.spacing[4],
  },
  cardHeaderRow: {
    flexDirection: 'row',
    justifyContent: 'space-between',
  },
  userInfo: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: theme.metrics.spacing[4],
  },
  infoContainer: {
    paddingHorizontal: theme.metrics.spacing[4],
    gap: theme.metrics.spacing[3],
  },
  cardInfoContainer: {
    gap: theme.metrics.spacing[3],
  },
  badgeRow: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: theme.metrics.spacing[4],
  },
  reasonSection: {
    paddingHorizontal: theme.metrics.spacing[4],
    marginBottom: theme.metrics.spacing[6],
  },
  cardReasonSection: {
    marginBottom: theme.metrics.spacing[6],
  },
  marginBottom8: {
    marginBottom: theme.metrics.spacing[2],
  },
  marginTop4: {
    marginTop: theme.metrics.spacing[1],
  },
}));