Skip to content

Commit 1528f34

Browse files
mohas22samhere06
authored andcommitted
updated currency,datetime,decimal components
1 parent 97d3d8c commit 1528f34

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

packages/angular-sdk-components/src/lib/_components/field/currency/currency.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class CurrencyComponent implements OnInit, OnDestroy {
130130
nValue = parseFloat(nValue);
131131
}
132132
this.value$ = nValue;
133+
this.fieldControl.setValue(this.value$);
133134
}
134135
this.helperText = this.configProps$.helperText;
135136
this.placeholder = this.configProps$.placeholder || '';

packages/angular-sdk-components/src/lib/_components/field/date-time/date-time.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import { MatInputModule } from '@angular/material/input';
66
import { MatFormFieldModule } from '@angular/material/form-field';
77
import { OwlDateTimeModule, OwlNativeDateTimeModule } from '@danielmoncada/angular-datetime-picker';
88
import { interval } from 'rxjs';
9+
import dayjs from 'dayjs';
10+
import moment from 'moment';
911
import { AngularPConnectData, AngularPConnectService } from '../../../_bridge/angular-pconnect';
1012
import { Utils } from '../../../_helpers/utils';
1113
import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component';
1214
import { dateFormatInfoDefault, getDateFormatInfo } from '../../../_helpers/date-format-utils';
1315
import { PConnFieldProps } from '../../../_types/PConnProps.interface';
1416
import { handleEvent } from '../../../_helpers/event-util';
1517
import { format } from '../../../_helpers/formatters';
18+
import DateFormatter from '../../../_helpers/formatters/date';
1619

1720
interface DateTimeProps extends PConnFieldProps {
1821
// If any, enter additional props that only exist on DateTime here
@@ -68,6 +71,7 @@ export class DateTimeComponent implements OnInit, OnDestroy {
6871
actionsApi: Object;
6972
propName: string;
7073
formattedValue$: any;
74+
timezone = PCore.getEnvironmentInfo()?.getTimeZone();
7175

7276
constructor(
7377
private angularPConnect: AngularPConnectService,
@@ -88,7 +92,7 @@ export class DateTimeComponent implements OnInit, OnDestroy {
8892
if (this.formGroup$) {
8993
// add control to formGroup
9094
this.formGroup$.addControl(this.controlName$, this.fieldControl);
91-
this.fieldControl.setValue(this.value$);
95+
this.fieldControl.setValue(dayjs(DateFormatter?.convertToTimezone(this.value$, { timezone: this.timezone }))?.toISOString());
9296
this.bHasForm$ = true;
9397
} else {
9498
this.bReadonly$ = true;
@@ -132,7 +136,7 @@ export class DateTimeComponent implements OnInit, OnDestroy {
132136
this.testId = this.configProps$.testId;
133137
this.helperText = this.configProps$.helperText;
134138
this.value$ = this.configProps$?.value;
135-
this.fieldControl.setValue(this.value$);
139+
this.fieldControl.setValue(dayjs(DateFormatter?.convertToTimezone(this.value$, { timezone: this.timezone }))?.toISOString());
136140
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
137141
setTimeout(() => {
138142
if (this.configProps$.required != null) {
@@ -186,7 +190,9 @@ export class DateTimeComponent implements OnInit, OnDestroy {
186190
// this comes from the date pop up
187191
if (typeof event.value === 'object') {
188192
// convert date to pega "date" format
189-
event.value = event.value?.toISOString();
193+
const dateTime = moment(event.value?.toISOString());
194+
const timeZoneDateTime = dayjs.tz(dateTime.format('YYYY-MM-DDTHH:mm:ss'), this.timezone);
195+
event.value = timeZoneDateTime && timeZoneDateTime.isValid() ? timeZoneDateTime.toISOString() : '';
190196
}
191197
handleEvent(this.actionsApi, 'changeNblur', this.propName, event.value);
192198
}

packages/angular-sdk-components/src/lib/_components/field/decimal/decimal.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
currencyMask
1313
[options]="{
1414
prefix: currencySymbol,
15+
suffix: suffix,
1516
thousands: thousandSeparator,
1617
decimal: decimalSeparator,
1718
align: 'left',

packages/angular-sdk-components/src/lib/_components/field/decimal/decimal.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class DecimalComponent implements OnInit, OnDestroy {
6565
formatter;
6666
formattedValue: any;
6767
inputMode: any;
68+
suffix = '';
6869

6970
constructor(
7071
private angularPConnect: AngularPConnectService,
@@ -136,6 +137,7 @@ export class DecimalComponent implements OnInit, OnDestroy {
136137
nValue = parseFloat(nValue);
137138
}
138139
this.value$ = nValue;
140+
this.fieldControl.setValue(this.value$);
139141
}
140142
this.helperText = this.configProps$.helperText;
141143
this.placeholder = this.configProps$.placeholder || '';
@@ -185,6 +187,11 @@ export class DecimalComponent implements OnInit, OnDestroy {
185187
if (this.bReadonly$ && this.formatter === 'Currency') {
186188
this.currencySymbol = theSymbols.theCurrencySymbol;
187189
}
190+
191+
if (this.bReadonly$ && this.formatter === 'Percentage') {
192+
this.suffix = '%';
193+
}
194+
188195
this.decimalPrecision = this.configProps$?.decimalPrecision ?? 2;
189196

190197
this.componentReference = this.pConn$.getStateProps().value;

packages/angular-sdk-components/src/lib/_components/field/phone/phone.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class PhoneComponent implements OnInit, OnDestroy {
117117
this.testId = this.configProps$.testId;
118118
if (this.configProps$.value != undefined) {
119119
this.value$ = this.configProps$.value;
120+
this.fieldControl.setValue(this.value$);
120121
}
121122
this.helperText = this.configProps$.helperText;
122123

packages/angular-sdk-components/src/lib/_helpers/formatters/common.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export function getLocale(locale: string = '') {
77
return Intl.DateTimeFormat().resolvedOptions().locale;
88
}
99

10-
export function getCurrentTimezone() {
11-
return PCore?.getEnvironmentInfo?.().getTimeZone?.();
10+
export function getCurrentTimezone(timezone?: string) {
11+
// use timezone if specified
12+
if (timezone) return timezone;
13+
return PCore?.getLocaleUtils?.().getTimeZoneInUse?.();
1214
}

packages/angular-sdk-components/src/lib/_helpers/formatters/format-utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ function CurrencyFormatter(
2727
currency
2828
});
2929

30-
let countryCode = currentLocale?.split('-')[1].toUpperCase();
30+
// For currency other than EUR, we need to determine the country code from currency code
31+
// If currency is EUR, we use the locale to determine the country code
32+
let countryCode: string | undefined;
33+
if (currency !== 'EUR') {
34+
countryCode = currency.substring(0, 2);
35+
} else {
36+
countryCode = currentLocale?.split('-')[1].toUpperCase();
37+
}
3138

3239
// If countryCode is still undefined, setting it as US
3340
if (!countryCode) {

0 commit comments

Comments
 (0)