Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit bdbe5b9

Browse files
committed
Added creation time column to payments' list.
1 parent a137ebf commit bdbe5b9

File tree

8 files changed

+42
-8
lines changed

8 files changed

+42
-8
lines changed

src/constants/workPeriods.js

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export const TAAS_TEAM_API_URL = `${API.V5}/taas-teams`;
3131
export const DATE_FORMAT_API = "YYYY-MM-DD";
3232
export const DATE_FORMAT_ISO = "YYYY-MM-DD";
3333
export const DATE_FORMAT_UI = "MMM DD, YYYY";
34+
export const DATETIME_FORMAT_UI = "MMM DD, YYYY h:mm a";
35+
36+
export const TIMEZONE_SOURCE = "America/New_York";
3437

3538
// Field names that are required to be retrieved for display, filtering and sorting.
3639
export const API_REQUIRED_FIELDS = [

src/routes/WorkPeriods/components/PaymentsList/index.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const PaymentsList = ({ className, daysPaid, daysWorked, payments }) => (
1919
<th>Weekly Rate</th>
2020
<th>Days</th>
2121
<th>Amount</th>
22+
<th className={styles.createdAt}>Created At</th>
2223
<th className={styles.paymentStatus}>Status</th>
2324
<th></th>
2425
</tr>

src/routes/WorkPeriods/components/PaymentsList/styles.module.scss

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ table.paymentsList {
2525
background: #f4f4f4;
2626

2727
&:first-child,
28+
&.createdAt,
2829
&.paymentStatus {
2930
text-align: left;
3031
}

src/routes/WorkPeriods/components/PaymentsListItem/index.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import PT from "prop-types";
55
import PaymentActions from "../PaymentActions";
66
import PaymentError from "../PaymentError";
77
import PaymentStatus from "../PaymentStatus";
8-
import { currencyFormatter, formatChallengeUrl } from "utils/formatters";
8+
import {
9+
currencyFormatter,
10+
formatChallengeUrl,
11+
formatDateTimeInTimeZone,
12+
} from "utils/formatters";
913
import { PAYMENT_STATUS } from "constants/workPeriods";
1014
import styles from "./styles.module.scss";
1115

@@ -55,6 +59,9 @@ const PaymentsListItem = ({ daysPaid, daysWorked, item }) => {
5559
</td>
5660
<td className={styles.days}>{item.days}</td>
5761
<td className={styles.amount}>{currencyFormatter.format(item.amount)}</td>
62+
<td className={styles.createdAt}>
63+
{formatDateTimeInTimeZone(item.createdAt)}
64+
</td>
5865
<td className={styles.paymentStatus}>
5966
<div className={styles.statusWithError}>
6067
<PaymentStatus status={item.status} />
@@ -84,6 +91,7 @@ PaymentsListItem.propTypes = {
8491
id: PT.oneOfType([PT.string, PT.number]).isRequired,
8592
amount: PT.number.isRequired,
8693
challengeId: PT.oneOfType([PT.string, PT.number]),
94+
createdAt: PT.number.isRequired,
8795
days: PT.number.isRequired,
8896
memberRate: PT.number.isRequired,
8997
status: PT.string.isRequired,

src/routes/WorkPeriods/components/PaymentsListItem/styles.module.scss

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
text-align: right;
5959
}
6060

61+
.createdAt {
62+
text-align: left;
63+
}
64+
6165
.paymentStatus {
6266
white-space: nowrap;
6367
}

src/utils/formatters.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import moment from "moment";
1+
import moment from "moment-timezone";
22
import isNumber from "lodash/isNumber";
3-
import { DATE_FORMAT_UI, PAYMENT_STATUS_LABELS } from "constants/workPeriods";
3+
import {
4+
DATETIME_FORMAT_UI,
5+
DATE_FORMAT_UI,
6+
PAYMENT_STATUS_LABELS,
7+
TIMEZONE_SOURCE,
8+
} from "constants/workPeriods";
49
import {
510
PLATFORM_WEBSITE_URL,
611
TAAS_BASE_PATH,
@@ -29,6 +34,19 @@ export function formatDate(date) {
2934
return date ? moment(date).format(DATE_FORMAT_UI) : "-";
3035
}
3136

37+
const TIMEZONE_BROWSER = moment.tz.guess();
38+
39+
/**
40+
* Formats the date and time using the provided timezone.
41+
*
42+
* @param {*} dateTime value that can be parsed by Moment
43+
* @param {string} [tz] timezone in which the resulting time will be displayed
44+
* @returns {string}
45+
*/
46+
export function formatDateTimeInTimeZone(dateTime, tz = TIMEZONE_BROWSER) {
47+
return moment.tz(dateTime, TIMEZONE_SOURCE).tz(tz).format(DATETIME_FORMAT_UI);
48+
}
49+
3250
/**
3351
* Returns a string denoting whether the specified start date corresponds to the
3452
* current period or future period.

src/utils/misc.js

-1
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,3 @@ export function validateAmount(value) {
253253
amount < 1e5
254254
);
255255
}
256-

src/utils/workPeriods.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import moment from "moment";
1+
import moment from "moment-timezone";
22
import {
33
ALERT,
44
API_CHALLENGE_PAYMENT_STATUS_MAP,
55
API_PAYMENT_STATUS_MAP,
6-
DATE_FORMAT_API,
76
DATE_FORMAT_ISO,
87
PAYMENT_STATUS,
98
REASON_DISABLED,
9+
TIMEZONE_SOURCE,
1010
URL_QUERY_PARAM_MAP,
1111
} from "constants/workPeriods";
1212

@@ -127,7 +127,7 @@ export function makeUrlQuery(state) {
127127
const { pageNumber, pageSize } = pagination;
128128
const { criteria, order } = sorting;
129129
const params = {
130-
startDate: dateRange[0].format(DATE_FORMAT_API),
130+
startDate: dateRange[0].format(DATE_FORMAT_ISO),
131131
paymentStatuses: Object.keys(paymentStatuses).join(",").toLowerCase(),
132132
alertOptions: Object.keys(alertOptions).join(",").toLowerCase(),
133133
onlyFailedPayments: onlyFailedPayments ? "y" : "",
@@ -230,7 +230,7 @@ export function normalizePeriodData(period) {
230230
export function normalizePeriodPayments(payments, data) {
231231
let lastFailedPayment = null;
232232
for (let payment of payments) {
233-
payment.createdAt = moment(payment.createdAt).valueOf();
233+
payment.createdAt = moment.tz(payment.createdAt, TIMEZONE_SOURCE).valueOf();
234234
payment.status = normalizeChallengePaymentStatus(payment.status);
235235
if (payment.status === PAYMENT_STATUS.FAILED) {
236236
lastFailedPayment = payment;

0 commit comments

Comments
 (0)