Skip to content

Commit 7b72366

Browse files
author
Joe Niemi
authored
Merge pull request #1988 from HSLdevcom/1987_trim_whitespaces_before_saving
1987 trim whitespaces before saving
2 parents 6d517df + a808996 commit 7b72366

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/utils/HttpUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import EndpointPath from '~/enums/endpointPath';
55
import FetchStatusCode from '~/enums/fetchStatusCode';
66
import ApolloClient from '~/helpers/ApolloClient';
77
import IError from '~/models/IError';
8+
import { trimObjectWhiteSpaces } from '~/utils/trimWhiteSpaces';
89
import AlertStore from '~/stores/alertStore';
910
import LoginStore from '~/stores/loginStore';
1011

@@ -83,7 +84,7 @@ class HttpUtils {
8384
object: any,
8485
credentials?: credentials
8586
) => {
86-
const formattedObject = _format(object);
87+
const formattedObject = _format(trimObjectWhiteSpaces(object));
8788
let error: IError | null = null;
8889

8990
try {

src/utils/trimWhiteSpaces.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const trimStrings = (key: unknown, value: unknown) => {
2+
if (typeof value === 'string') {
3+
return value.trim();
4+
}
5+
6+
return value;
7+
};
8+
9+
// Taken from here: https://codepen.io/ajmueller/pen/NyXNME
10+
export const trimObjectWhiteSpaces = (object: Object) => {
11+
return JSON.parse(JSON.stringify(object, trimStrings, 4));
12+
};

0 commit comments

Comments
 (0)