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

100% Statements 14/14
100% Branches 9/9
100% Functions 4/4
100% Lines 13/13

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                              3x                 8x 8x 8x   8x   8x 7x                                                                                   8x 1x                                                           8x 2x                             6x     8x                                                                                                                                    
import React from 'react';
import { View } 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';
 
import { RequestCategory } from '@/types/request';
 
import { Skeleton } from './skeletons/Skeleton';
import { getRequestInfoSkeleton } from './skeletons';
 
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 InfoSkeleton = getRequestInfoSkeleton(category);
 
  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 */}
          <InfoSkeleton />
 
          {/* 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>
        <View style={{ paddingHorizontal: theme.metrics.spacing[4] }}>
          <HeaderRequest
            title="Request Detail"
            onBackStep={navigation.goBack}
            isShowBackButton
            isShowCloseButton={false}
          />
        </View>
        {renderDetailSkeleton()}
      </ScreenLayout>
    );
  }
 
  return type === 'card' ? renderCardSkeleton() : renderDetailSkeleton();
};
 
const useStyles = makeStyles(theme => ({
  container: {
    paddingTop: theme.metrics.spacing[4],
    margin: 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],
  },
}));