| @@ -25,8 +25,9 @@ | ||
| 25 | 25 | BulkActionToolbar, |
| 26 | 26 | Table as SharedTable, |
| 27 | 27 | } from "../components/shared"; |
| 28 | 28 | import { __ } from "../lib/i18n"; |
| 29 | +import { toDateValue } from "../lib/dateFormat"; | |
| 29 | 30 | import { usePermissions } from "../hooks/usePermissions"; |
| 30 | 31 | import { useToast } from "../components/ui/toast"; |
| 31 | 32 | import { apiClient } from "../lib/api-client"; |
| 32 | 33 | import { getErrorContext } from "../lib/errors"; |
| @@ -184,9 +185,9 @@ | ||
| 184 | 185 | params: queryParams, |
| 185 | 186 | }); |
| 186 | 187 | return response; |
| 187 | 188 | }, |
| 188 | - enabled: can("yatra_view_bookings"), | |
| 189 | + enabled: can("yatra_manage_discounts"), | |
| 189 | 190 | }); |
| 190 | 191 | |
| 191 | 192 | const { data: discountStats } = useQuery({ |
| 192 | 193 | queryKey: ["discounts-stats"], |
| @@ -202,9 +203,9 @@ | ||
| 202 | 203 | expired: 0, |
| 203 | 204 | }; |
| 204 | 205 | } |
| 205 | 206 | }, |
| 206 | - enabled: can("yatra_view_bookings"), | |
| 207 | + enabled: can("yatra_manage_discounts"), | |
| 207 | 208 | }); |
| 208 | 209 | |
| 209 | 210 | const discountStatusCounts = useMemo(() => { |
| 210 | 211 | const d = discountStats as Record<string, unknown> | null | undefined; |
| @@ -285,9 +286,10 @@ | ||
| 285 | 286 | |
| 286 | 287 | const formatDate = (dateString: string) => { |
| 287 | 288 | if (!dateString) return __("N/A", "yatra"); |
| 288 | 289 | try { |
| 289 | - const date = new Date(dateString); | |
| 290 | + // toDateValue: a date-only expiry_date must not roll back a day in behind-UTC zones. | |
| 291 | + const date = toDateValue(dateString); | |
| 290 | 292 | return date.toLocaleDateString("en-US", { |
| 291 | 293 | month: "short", |
| 292 | 294 | day: "numeric", |
| 293 | 295 | year: "numeric", |
| @@ -723,11 +725,15 @@ | ||
| 723 | 725 | <div className="flex items-center gap-1"> |
| 724 | 726 | <span className="font-medium text-gray-900 dark:text-white"> |
| 725 | 727 | {discount.type === "percentage" |
| 726 | 728 | ? `${discount.amount}%` |
| 727 | - : formatYatraMoney(Number(discount.amount) || 0, adminCurrency, { | |
| 728 | - zeroAsUnknown: false, | |
| 729 | - })} | |
| 729 | + : formatYatraMoney( | |
| 730 | + Number(discount.amount) || 0, | |
| 731 | + adminCurrency, | |
| 732 | + { | |
| 733 | + zeroAsUnknown: false, | |
| 734 | + }, | |
| 735 | + )} | |
| 730 | 736 | </span> |
| 731 | 737 | <span className="text-xs text-gray-500"> |
| 732 | 738 | {__("off", "yatra")} |
| 733 | 739 | </span> |
| @@ -1102,9 +1108,9 @@ | ||
| 1102 | 1108 | description={__( |
| 1103 | 1109 | "Create and manage discount coupons for your trips", |
| 1104 | 1110 | "yatra", |
| 1105 | 1111 | )} |
| 1106 | - actionCapability="yatra_edit_bookings" | |
| 1112 | + actionCapability="yatra_manage_discounts" | |
| 1107 | 1113 | actions={ |
| 1108 | 1114 | <Button |
| 1109 | 1115 | onClick={handleCreateDiscount} |
| 1110 | 1116 | className="flex items-center gap-2" |
| @@ -1162,9 +1168,9 @@ | ||
| 1162 | 1168 | </div> |
| 1163 | 1169 | </CardContent> |
| 1164 | 1170 | </Card> |
| 1165 | 1171 | |
| 1166 | - <ConditionalRender capability="yatra_view_bookings"> | |
| 1172 | + <ConditionalRender capability="yatra_manage_discounts"> | |
| 1167 | 1173 | <> |
| 1168 | 1174 | <BulkActionToolbar |
| 1169 | 1175 | selectedIds={selectedIds} |
| 1170 | 1176 | bulkAction={bulkAction} |
| @@ -1214,9 +1220,11 @@ | ||
| 1214 | 1220 | "yatra", |
| 1215 | 1221 | ) |
| 1216 | 1222 | } |
| 1217 | 1223 | onCreateClick={ |
| 1218 | - can("yatra_edit_bookings") ? handleCreateDiscount : undefined | |
| 1224 | + can("yatra_manage_discounts") | |
| 1225 | + ? handleCreateDiscount | |
| 1226 | + : undefined | |
| 1219 | 1227 | } |
| 1220 | 1228 | onSort={handleSort} |
| 1221 | 1229 | getSortIcon={getSortIcon} |
| 1222 | 1230 | selectedItemIds={selectedIds} |
| @@ -1224,9 +1232,9 @@ | ||
| 1224 | 1232 | onSelectAll={handleSelectAll} |
| 1225 | 1233 | isAllSelected={isAllSelected} |
| 1226 | 1234 | getItemId={(discount: Discount) => discount.id} |
| 1227 | 1235 | skeletonRows={5} |
| 1228 | - capability="yatra_view_bookings" | |
| 1236 | + capability="yatra_manage_discounts" | |
| 1229 | 1237 | /> |
| 1230 | 1238 | </CardContent> |
| 1231 | 1239 | </Card> |
| 1232 | 1240 | |