@towsila/expo-ui-library 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/ui/requestCard.tsx +118 -66
- package/src/index.ts +1 -1
- package/src/types/request.ts +13 -17
package/package.json
CHANGED
|
@@ -1,41 +1,58 @@
|
|
|
1
1
|
import { View, Text } from "react-native";
|
|
2
|
-
import { SvgProps } from "react-native-svg";
|
|
3
2
|
import Clock from "@/assets/images/icons/clock.svg";
|
|
4
3
|
import Destination from "@/assets/images/icons/destination.svg";
|
|
5
4
|
import Flag from "@/assets/images/icons/flag.svg";
|
|
6
5
|
import Warning from "@/assets/images/icons/warning.svg";
|
|
7
|
-
import {
|
|
6
|
+
import { SvgProps } from "react-native-svg";
|
|
8
7
|
import { useAppTheme } from "../../context/ThemeContext";
|
|
8
|
+
import { useRelativeTime } from "../../hooks/useRelativeTime";
|
|
9
9
|
import { useLanguage } from "../../context/LanguageContext";
|
|
10
|
+
import {Request} from "../../types/request";
|
|
10
11
|
import { Fonts, textSize } from "../../tokens/typography";
|
|
11
12
|
import CircularCountdown from "./circularCountdown";
|
|
12
13
|
import { formatPrice } from "../../utils/formatPrice";
|
|
14
|
+
export default function RequestCard({
|
|
15
|
+
request,
|
|
16
|
+
addRow = false,
|
|
17
|
+
onExpire,
|
|
18
|
+
t,
|
|
19
|
+
locationName,
|
|
20
|
+
destinationName,
|
|
21
|
+
}: { request: Request, addRow?: boolean, onExpire?: (id:string)=>void, t: (key: string, opts?: any) => string; locationName: string; destinationName: string;}) {
|
|
22
|
+
const {colors} = useAppTheme();
|
|
23
|
+
const formatRelative = useRelativeTime(t);
|
|
24
|
+
const {isRTL} = useLanguage();
|
|
25
|
+
const statusColors = {
|
|
26
|
+
PENDING: colors.semantic.warning,
|
|
27
|
+
CONFIRMED: colors.semantic.success,
|
|
28
|
+
REJECTED: colors.semantic.error,
|
|
29
|
+
CANCELLED: colors.text.placeholder,
|
|
30
|
+
AWAITING_PICK_UP: colors.semantic.warning,
|
|
31
|
+
PICK_UP:colors.semantic.warning,
|
|
32
|
+
DROP_OFF:colors.semantic.warning,
|
|
33
|
+
EXPIRED: colors.text.placeholder,
|
|
34
|
+
};
|
|
13
35
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
addRow?: boolean;
|
|
26
|
-
onExpire?: (id: string) => void;
|
|
27
|
-
}
|
|
36
|
+
const statusLabels = {
|
|
37
|
+
PENDING: t("request.status.PENDING"),
|
|
38
|
+
CONFIRMED: t("request.status.CONFIRMED"),
|
|
39
|
+
REJECTED: t("request.status.REJECTED"),
|
|
40
|
+
CANCELLED: t("request.status.CANCELLED"),
|
|
41
|
+
AWAITING_PICK_UP:t("request.status.AWAITING_PICK_UP"),
|
|
42
|
+
PICK_UP:t("request.status.PICK_UP"),
|
|
43
|
+
DROP_OFF:t("request.status.DROP_OFF"),
|
|
44
|
+
EXPIRED: t("request.status.EXPIRED")
|
|
45
|
+
};
|
|
46
|
+
const result = t("request.time.ago", { time: formatRelative(request.time) });
|
|
28
47
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { colors } = useAppTheme();
|
|
35
|
-
const { isRTL } = useLanguage();
|
|
36
|
-
const rowDir = isRTL ? "row" : "row-reverse";
|
|
48
|
+
// const locationName = shortAddress(usePlaceName(request.location)); // [lat, lng]
|
|
49
|
+
// const destinationName =shortAddress(usePlaceName(request.destination));
|
|
50
|
+
const carStateText = request.carState
|
|
51
|
+
.map((s) => t(`request.carStateEnum.${s}`))
|
|
52
|
+
.join(" - ");
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
|
|
55
|
+
const deadline = new Date(request.time).getTime() + 2 * 60 * 1000;
|
|
39
56
|
|
|
40
57
|
return (
|
|
41
58
|
<View
|
|
@@ -43,56 +60,85 @@ export default function RequestCard({
|
|
|
43
60
|
backgroundColor: colors.background.card,
|
|
44
61
|
borderRadius: 15,
|
|
45
62
|
padding: 12,
|
|
63
|
+
// marginBottom: 0,
|
|
46
64
|
borderWidth: 1.5,
|
|
47
65
|
borderColor: colors.text.primary,
|
|
48
|
-
gap: 10
|
|
66
|
+
gap: 10
|
|
49
67
|
}}
|
|
50
68
|
>
|
|
51
|
-
|
|
52
|
-
<View style={{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
<View style={{gap: 5}}>
|
|
70
|
+
<View style={{
|
|
71
|
+
flexDirection: isRTL ?"row":"row-reverse",
|
|
72
|
+
justifyContent: "space-between",
|
|
73
|
+
}}>
|
|
74
|
+
<Text
|
|
75
|
+
style={{
|
|
76
|
+
fontSize: textSize.lg,
|
|
77
|
+
fontFamily: Fonts.montserrat.bold,
|
|
78
|
+
color: colors.text.primary,
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
{request.name}
|
|
82
|
+
</Text>
|
|
83
|
+
<View
|
|
57
84
|
style={{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
85
|
+
backgroundColor: statusColors[request.status] + "20",
|
|
86
|
+
paddingHorizontal: 10,
|
|
87
|
+
paddingVertical: 4,
|
|
88
|
+
borderRadius: 20,
|
|
62
89
|
}}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
90
|
+
>
|
|
91
|
+
<Text
|
|
92
|
+
style={{
|
|
93
|
+
fontSize: textSize.sm,
|
|
94
|
+
fontFamily: Fonts.montserrat.regular,
|
|
95
|
+
color: statusColors[request.status],
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
{statusLabels[request.status]}
|
|
99
|
+
</Text>
|
|
100
|
+
</View>
|
|
68
101
|
</View>
|
|
69
|
-
|
|
70
102
|
{addRow && (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
103
|
+
<View style={{
|
|
104
|
+
flexDirection: isRTL ?"row":"row-reverse",
|
|
105
|
+
justifyContent: "space-between",
|
|
106
|
+
alignItems: "center",
|
|
107
|
+
}}>
|
|
108
|
+
<Text style={{
|
|
109
|
+
fontSize: textSize.xs,
|
|
110
|
+
fontFamily: Fonts.montserrat.regular,
|
|
111
|
+
color:colors.text.secondary
|
|
112
|
+
}}>
|
|
113
|
+
{request.phone} · {t(`request.vehicleType.${request.vehicleType}`)}
|
|
74
114
|
</Text>
|
|
75
|
-
{
|
|
76
|
-
<CircularCountdown deadline={deadline} onExpire={() => onExpire?.(
|
|
77
|
-
)
|
|
78
|
-
<View style={{
|
|
79
|
-
<View style={[isRTL
|
|
80
|
-
|
|
115
|
+
{request.status === "PENDING" ? (
|
|
116
|
+
<CircularCountdown deadline={deadline} onExpire={() => onExpire?.(request.id)}/>
|
|
117
|
+
):(
|
|
118
|
+
<View style={{flexDirection: isRTL ?"row":"row-reverse", alignItems: "center", gap: 4}}>
|
|
119
|
+
<View style={[isRTL && {transform :[{scaleX:-1}]}]}>
|
|
120
|
+
<Clock width={13} height={13} color={colors.text.placeholder} />
|
|
81
121
|
</View>
|
|
82
|
-
<Text
|
|
83
|
-
|
|
122
|
+
<Text
|
|
123
|
+
style={{
|
|
124
|
+
fontSize: textSize.xs,
|
|
125
|
+
fontFamily: Fonts.montserrat.regular,
|
|
126
|
+
color: colors.text.placeholder,
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
{result}
|
|
84
130
|
</Text>
|
|
85
|
-
|
|
131
|
+
</View>
|
|
86
132
|
)}
|
|
87
|
-
|
|
133
|
+
|
|
134
|
+
</View>
|
|
88
135
|
)}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
<View
|
|
136
|
+
</View>
|
|
137
|
+
<CardRow icon={Destination} label={t("request.pickUp")} value={locationName}/>
|
|
138
|
+
<CardRow icon={Flag} label={t("request.destination")} value={destinationName}/>
|
|
139
|
+
<CardRow icon={Warning} label={t("request.carState")} value={carStateText}/>
|
|
140
|
+
<View style={{borderWidth:0.5, borderColor: colors.semantic.border}}/>
|
|
141
|
+
<View
|
|
96
142
|
style={{
|
|
97
143
|
flexDirection: isRTL ? "row" : "row-reverse",
|
|
98
144
|
justifyContent: "space-between",
|
|
@@ -106,7 +152,7 @@ export default function RequestCard({
|
|
|
106
152
|
fontFamily: Fonts.montserrat.regular,
|
|
107
153
|
}}
|
|
108
154
|
>
|
|
109
|
-
{
|
|
155
|
+
{t("request.total")}
|
|
110
156
|
</Text>
|
|
111
157
|
<Text
|
|
112
158
|
style={[
|
|
@@ -117,10 +163,10 @@ export default function RequestCard({
|
|
|
117
163
|
},
|
|
118
164
|
]}
|
|
119
165
|
>
|
|
120
|
-
{`${formatPrice(
|
|
166
|
+
{`${formatPrice(request.price)} ${t("request.price.unit")}`}
|
|
121
167
|
</Text>
|
|
122
168
|
</View>
|
|
123
|
-
|
|
169
|
+
</View>
|
|
124
170
|
);
|
|
125
171
|
}
|
|
126
172
|
|
|
@@ -128,7 +174,13 @@ function CardRow({ icon: Icon, label, value }: { icon: React.ComponentType<SvgPr
|
|
|
128
174
|
const { isRTL } = useLanguage();
|
|
129
175
|
const { colors } = useAppTheme();
|
|
130
176
|
return (
|
|
131
|
-
<View
|
|
177
|
+
<View
|
|
178
|
+
style={{
|
|
179
|
+
flexDirection: isRTL ? "row" : "row-reverse",
|
|
180
|
+
alignItems: "center",
|
|
181
|
+
gap: 10,
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
132
184
|
<View style={{ flexShrink: 0 }}>
|
|
133
185
|
<Icon color={colors.primary} width={20} height={20} />
|
|
134
186
|
</View>
|
package/src/index.ts
CHANGED
|
@@ -80,4 +80,4 @@ export {RouteInfo} from "./types/route";
|
|
|
80
80
|
export {default as PhonePrefix} from "./components/ui/phonePrefix";
|
|
81
81
|
export {default as ProfileScreen} from "./components/screens/profileScreen";
|
|
82
82
|
export { default as RequestCard } from "./components/ui/requestCard";
|
|
83
|
-
export {
|
|
83
|
+
export { Request, RequestStatus } from "./types/request";
|
package/src/types/request.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
carState: string;
|
|
15
|
-
total: string;
|
|
16
|
-
currency: string; // t("request.price.unit")
|
|
17
|
-
};
|
|
1
|
+
export type RequestStatus = "PENDING" | "CONFIRMED" | "REJECTED" | "CANCELLED" | "AWAITING_PICK_UP" | "PICK_UP" |"DROP_OFF" | "EXPIRED"
|
|
2
|
+
export type Request = {
|
|
3
|
+
id: string;
|
|
4
|
+
vehicleType: string;
|
|
5
|
+
name: string;
|
|
6
|
+
phone: string;
|
|
7
|
+
location: [number, number];
|
|
8
|
+
destination: [number, number];
|
|
9
|
+
status:RequestStatus;
|
|
10
|
+
price: number;
|
|
11
|
+
time: string;
|
|
12
|
+
carState:string[];
|
|
13
|
+
}
|