Skip to content

Commit 2961574

Browse files
frozenheliumsamshara
authored andcommitted
Add date format to printable date output
1 parent ce37f07 commit 2961574

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/components/TextOutput/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function TextOutput(props: Props) {
6565
} = props;
6666

6767
const { value: propValue } = props;
68-
let valueComponent: React.ReactNode = propValue || invalidText;
68+
let valueComponent: React.ReactNode = invalidText;
6969

7070
if (otherProps.valueType === 'number') {
7171
valueComponent = (
@@ -91,6 +91,8 @@ function TextOutput(props: Props) {
9191
invalidText={invalidText}
9292
/>
9393
);
94+
} else if (!(propValue instanceof Date)) {
95+
valueComponent = propValue || invalidText;
9496
}
9597

9698
return (

src/components/printable/TextOutput/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { _cs } from '@togglecorp/fujs';
33
import NumberOutput, { Props as NumberOutputProps } from '#components/NumberOutput';
44
import BooleanOutput, { Props as BooleanOutputProps } from '#components/BooleanOutput';
55
import DateOutput, { Props as DateOutputProps } from '#components/DateOutput';
6+
import { DEFAULT_PRINT_DATE_FORMAT } from '#utils/constants';
67

78
import styles from './styles.module.css';
89

@@ -59,7 +60,7 @@ function TextOutput(props: Props) {
5960
} = props;
6061

6162
const { value: propValue } = props;
62-
let valueComponent: React.ReactNode = propValue || invalidText;
63+
let valueComponent: React.ReactNode = invalidText;
6364

6465
if (otherProps.valueType === 'number') {
6566
valueComponent = (
@@ -75,6 +76,7 @@ function TextOutput(props: Props) {
7576
// eslint-disable-next-line react/jsx-props-no-spreading
7677
{...otherProps}
7778
invalidText={invalidText}
79+
format={DEFAULT_PRINT_DATE_FORMAT}
7880
/>
7981
);
8082
} else if (otherProps.valueType === 'boolean') {
@@ -85,6 +87,8 @@ function TextOutput(props: Props) {
8587
invalidText={invalidText}
8688
/>
8789
);
90+
} else if (!(propValue instanceof Date)) {
91+
valueComponent = propValue || invalidText;
8892
}
8993

9094
return (

src/utils/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type components } from '#generated/types';
22

3-
export const DEFAULT_DATE_FORMAT = 'dd-MM-yyyy';
3+
export const DEFAULT_DATE_FORMAT = 'yyyy-MM-dd';
4+
export const DEFAULT_PRINT_DATE_FORMAT = 'dd-MM-yyyy';
45

56
// Alert
67

0 commit comments

Comments
 (0)