Skip to content

Commit

Permalink
OY-4885: Rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Marokhonov committed Sep 24, 2024
1 parent e424e96 commit 468febe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/main/app/src/utils/form/createErrorBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { differenceInMonths } from 'date-fns';
import _ from 'lodash';
import _fp from 'lodash/fp';

import {
formValueExists as exists,
Expand Down Expand Up @@ -149,6 +150,43 @@ class ErrorBuilder {
return this;
}

//Jos oppilaitoksen osan hakijapalveluille on annettu yhteystietoja, on nimi pakollinen ainakin yhdellä kielellä.
validateHakijapalveluidenYhteystiedot(
path,
{ message = null, languages = [] } = {}
) {
console.log('path', path);
console.log('thus', this);
if (!this.isVisible(path)) {
return this;
}

const hpy = this.getValue(path);
if (!hpy) {
return this;
}

const pickTranslations = _fp.pick(languages || []);
const hasNonemptyKieliversio = v =>
v &&
Object.values(pickTranslations(v)).some(n => String(n).trim().length > 0);

const validateYhteystiedot = (Object.values(hpy) || []).some(v =>
hasNonemptyKieliversio(v)
);

if (
validateYhteystiedot &&
!Object.values(pickTranslations(hpy.nimi)).some(
n => String(n).trim().length > 0
)
) {
languages.forEach(l => this.setError(`${path}.nimi.${l}`, message));
}

return this;
}

validateArrayMinLength(
path,
min,
Expand Down Expand Up @@ -259,6 +297,9 @@ export const validateTranslations = bindValidator('validateTranslations');
export const validateUrl = bindValidator('validateUrl');
export const validateInteger = bindValidator('validateInteger');
export const validateArchiveDate = bindValidator('validateArchiveDate');
export const validateHakijapalveluidenYhteystiedot = bindValidator(
'validateHakijapalveluidenYhteystiedot'
);

export const createErrorBuilder = (
values,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _fp from 'lodash/fp';

import createErrorBuilder, {
validateArrayMinLength,
validateHakijapalveluidenYhteystiedot,
} from '#/src/utils/form/createErrorBuilder';
import {
getKielivalinta,
Expand All @@ -16,7 +17,11 @@ export const validateOppilaitoksenOsaForm = values => {
validateArrayMinLength('kieliversiot', 1),
validateIfJulkaistu(eb =>
eb.validateTranslations('perustiedot.wwwSivuUrl', kieliversiot)
)
),
validateHakijapalveluidenYhteystiedot('hakijapalveluidenYhteystiedot', {
message: 'validointivirheet.nimiJollainKielellaPakollinen',
languages: kieliversiot,
})
)(createErrorBuilder(values))
.getErrors();
};

0 comments on commit 468febe

Please sign in to comment.