@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towsila/expo-ui-library",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -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 { RequestCardData, RequestCardLabels } from "../../types/request";
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
- interface Props {
15
- data: RequestCardData;
16
- labels: RequestCardLabels;
17
- statusLabel: string;
18
- statusColor: string;
19
- vehicleLabel: string; // already translated
20
- carStateText: string; // already translated and joined
21
- locationName: string;
22
- destinationName: string;
23
- agoText: string; // already built: "5 minutes ago"
24
- showCountdown?: boolean; // true when the app considers the request pending
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
- export default function RequestCard({
30
- data, labels, statusLabel, statusColor, vehicleLabel, carStateText,
31
- locationName, destinationName, agoText,
32
- showCountdown = false, addRow = false, onExpire,
33
- }: Props) {
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
- const deadline = new Date(data.time).getTime() + 2 * 60 * 1000;
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
- <View style={{ gap: 5 }}>
52
- <View style={{ flexDirection: rowDir, justifyContent: "space-between" }}>
53
- <Text style={{ fontSize: textSize.lg, fontFamily: Fonts.montserrat.bold, color: colors.text.primary }}>
54
- {data.name}
55
- </Text>
56
- <View
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
- backgroundColor: statusColor + "20",
59
- paddingHorizontal: 10,
60
- paddingVertical: 4,
61
- borderRadius: 20,
85
+ backgroundColor: statusColors[request.status] + "20",
86
+ paddingHorizontal: 10,
87
+ paddingVertical: 4,
88
+ borderRadius: 20,
62
89
  }}
63
- >
64
- <Text style={{ fontSize: textSize.sm, fontFamily: Fonts.montserrat.regular, color: statusColor }}>
65
- {statusLabel}
66
- </Text>
67
- </View>
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
- <View style={{ flexDirection: rowDir, justifyContent: "space-between", alignItems: "center" }}>
72
- <Text style={{ fontSize: textSize.xs, fontFamily: Fonts.montserrat.regular, color: colors.text.secondary }}>
73
- {data.phone} · {vehicleLabel}
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
- {showCountdown ? (
76
- <CircularCountdown deadline={deadline} onExpire={() => onExpire?.(data.id)} />
77
- ) : (
78
- <View style={{ flexDirection: rowDir, alignItems: "center", gap: 4 }}>
79
- <View style={[isRTL && { transform: [{ scaleX: -1 }] }]}>
80
- <Clock width={13} height={13} color={colors.text.placeholder} />
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 style={{ fontSize: textSize.xs, fontFamily: Fonts.montserrat.regular, color: colors.text.placeholder }}>
83
- {agoText}
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
- </View>
131
+ </View>
86
132
  )}
87
- </View>
133
+
134
+ </View>
88
135
  )}
89
- </View>
90
-
91
- <CardRow icon={Destination} label={labels.pickUp} value={locationName} />
92
- <CardRow icon={Flag} label={labels.destination} value={destinationName} />
93
- <CardRow icon={Warning} label={labels.carState} value={carStateText} />
94
- <View style={{ borderWidth: 0.5, borderColor: colors.semantic.border }} />
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
- {labels.total}
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(data.price)} ${labels.currency}`}
166
+ {`${formatPrice(request.price)} ${t("request.price.unit")}`}
121
167
  </Text>
122
168
  </View>
123
- </View>
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 style={{ flexDirection: isRTL ? "row" : "row-reverse", alignItems: "center", gap: 10 }}>
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 { RequestCardData, RequestCardLabels } from "./types/request";
83
+ export { Request, RequestStatus } from "./types/request";
@@ -1,17 +1,13 @@
1
- export type RequestCardData = {
2
- id: string;
3
- name: string; // client name (provider app) or provider name (client app)
4
- phone: string;
5
- time: string; // ISO string, used for the countdown deadline
6
- price: number;
7
- location: [number, number]; // [lat, lng]
8
- destination: [number, number]; // [lat, lng]
9
- };
10
-
11
- export type RequestCardLabels = {
12
- pickUp: string;
13
- destination: string;
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
+ }