From 766d98d7533b81b43ab900e2714b8c30064ea7cf Mon Sep 17 00:00:00 2001 From: samshara Date: Tue, 26 Nov 2024 18:24:40 +0545 Subject: [PATCH] fix: auto-prefix `https://` for incomplete URLs in source information field --- .changeset/wise-flowers-greet.md | 5 +++++ app/src/utils/importTemplate.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changeset/wise-flowers-greet.md diff --git a/.changeset/wise-flowers-greet.md b/.changeset/wise-flowers-greet.md new file mode 100644 index 000000000..aebeb0826 --- /dev/null +++ b/.changeset/wise-flowers-greet.md @@ -0,0 +1,5 @@ +--- +"go-web-app": patch +--- + +Auto append https:// for incomplete URLs in [#1505](https://github.com/IFRCGo/go-web-app/issues/1505) diff --git a/app/src/utils/importTemplate.ts b/app/src/utils/importTemplate.ts index cd4820387..1c63e6c35 100644 --- a/app/src/utils/importTemplate.ts +++ b/app/src/utils/importTemplate.ts @@ -346,6 +346,18 @@ export function getValueFromImportTemplate< if (schema.type === 'input') { const value = formValues[fieldName]; + if ( + (fieldName === 'source_information__source__0__source_link' + || fieldName === 'source_information__source__1__source_link' + || fieldName === 'source_information__source__2__source_link' + || fieldName === 'source_information__source__3__source_link' + || fieldName === 'source_information__source__4__source_link' + ) + && isDefined(value) && (typeof value === 'string') && !value.includes('://') + ) { + // TODO: we need to find a better solution to this + return `https://${value}`; + } // TODO: add validation from schema.validation return value; }