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 | 3x 13x 13x 13x 13x 13x 13x 5x 5x 2x 1x 1x 1x 8x 13x 13x | import React from 'react';
import { Image, Text, View } from 'react-native';
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { PROCESSING_BY_RESPONSE } from '@/constants/apis';
import { ACTION_MAP, HISTORY_ACTION_MESSAGES } from '@/constants/request';
import { Activity } from '@/types/request';
import { ActivityState, RequestCategory } from '@/types/request';
type Props = {
activity: Activity;
isLast?: boolean;
processingBy?: string;
category?: string;
};
export const ApprovalTimelineItem = ({ activity, isLast, processingBy, category }: Props) => {
const styles = useStyles();
const date = new Date(activity.occurredAt);
const day = date
.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
})
.toUpperCase();
const time = date.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
});
const renderActivityAction = () => {
switch (category) {
case RequestCategory.MAINTENANCE: {
const isProcessing = processingBy !== PROCESSING_BY_RESPONSE.NONE;
switch (true) {
case activity.action === ActivityState.CANCEL || activity.state === ActivityState.CANCEL:
return HISTORY_ACTION_MESSAGES.CANCELLED;
case isProcessing && activity.state === ActivityState.PENDING:
return HISTORY_ACTION_MESSAGES.PROCEEDED;
case isProcessing && activity.action === ActivityState.DONE:
return HISTORY_ACTION_MESSAGES.COMPLETED;
default:
return HISTORY_ACTION_MESSAGES.CLOSED;
}
}
default:
return (
(activity.action && ACTION_MAP[activity.action]) ||
(activity.isApproved
? HISTORY_ACTION_MESSAGES.APPROVED
: HISTORY_ACTION_MESSAGES.REJECTED)
);
}
};
return (
<View style={styles.container}>
{/* LEFT: AVATAR + TIMELINE */}
<View style={styles.left}>
{/* Avatar */}
<Image source={{ uri: activity.avatar }} style={styles.avatar} />
{/* Timeline */}
{!isLast && (
<View style={styles.timeline}>
<View style={styles.line} />
<View style={styles.dot} />
</View>
)}
</View>
{/* RIGHT: CONTENT */}
<View style={styles.content}>
<Text style={styles.title}>
<Text style={styles.name}>{activity.name}</Text> {renderActivityAction()}
</Text>
<Text style={styles.meta}>
{day} | {time}
</Text>
<Text style={styles.meta}>{activity.note}</Text>
</View>
</View>
);
};
const useStyles = makeStyles(theme => ({
container: {
flexDirection: 'row',
paddingVertical: theme.metrics.spacing[2],
},
/* LEFT COLUMN */
left: {
alignItems: 'center',
},
avatar: {
width: theme.metrics.spacing[12.5],
height: theme.metrics.spacing[12.5],
borderRadius: theme.metrics.borderRadius[6],
marginBottom: theme.metrics.spacing[1],
},
/* TIMELINE */
timeline: {
alignItems: 'center',
flex: 1,
},
dot: {
width: theme.metrics.spacing[2],
height: theme.metrics.spacing[2],
borderRadius: theme.metrics.borderRadius[1],
backgroundColor: theme.colors.text.tertiary,
},
line: {
flex: 1,
width: theme.metrics.spacing[0.25],
height: theme.metrics.spacing[5],
backgroundColor: theme.colors.text.tertiary,
marginBottom: theme.metrics.spacing[0.5],
},
/* CONTENT */
content: {
flex: 1,
paddingLeft: theme.metrics.spacing[2],
paddingTop: theme.metrics.spacing[1],
},
title: {
fontSize: theme.metrics.textSize[18],
color: theme.colors.text.primary,
},
name: {
fontWeight: theme.metrics.fontWeight.semiBold,
},
meta: {
marginTop: theme.metrics.spacing[1],
fontSize: theme.metrics.textSize[12],
color: theme.colors.text.tertiary,
letterSpacing: 0.5,
},
}));
|