diff --git a/public/editor-client/src/ekklesia/index.ts b/public/editor-client/src/ekklesia/index.ts index 07c70b1e9e..64aa1f75d8 100644 --- a/public/editor-client/src/ekklesia/index.ts +++ b/public/editor-client/src/ekklesia/index.ts @@ -1,6 +1,7 @@ import { Config } from "config"; import { ChoicesAsync, ChoicesSync } from "types/Choices"; import { + EkklesiaExtra, EkklesiaFieldMap, EkklesiaFields, EkklesiaKeys, @@ -14,7 +15,8 @@ export const getEkklesiaFields = (config: Config) => ({ async handler( res: Response, rej: Response, - keys: EkklesiaParams + keys: EkklesiaParams, + extra?: EkklesiaExtra ): Promise { const { ekklesiaApiUrl } = config.api; if (!ekklesiaApiUrl) { @@ -25,7 +27,7 @@ export const getEkklesiaFields = (config: Config) => ({ return; } try { - const fields = await getFields(ekklesiaApiUrl, keys); + const fields = await getFields(ekklesiaApiUrl, keys, extra); res(fields); } catch (error) { if (process.env.NODE_ENV === "development") { @@ -42,7 +44,8 @@ export const updateEkklesiaFields = (config: Config) => ({ rej: Response, keys: { fields: Array; - } + }, + extra?: EkklesiaExtra ): Promise { const { ekklesiaApiUrl } = config.api; @@ -57,7 +60,11 @@ export const updateEkklesiaFields = (config: Config) => ({ const dataToChange: EkklesiaKeys = {}; try { for (const field of keys.fields) { - const choiches = await getFields(ekklesiaApiUrl, field.module); + const choiches = await getFields( + ekklesiaApiUrl, + field.module, + extra + ); if (!choiches.length) continue; diff --git a/public/editor-client/src/ekklesia/utils.ts b/public/editor-client/src/ekklesia/utils.ts index 88f59ff865..17cd0a7fc3 100644 --- a/public/editor-client/src/ekklesia/utils.ts +++ b/public/editor-client/src/ekklesia/utils.ts @@ -1,16 +1,16 @@ +import { Obj, Str } from "@brizy/readers"; import { request } from "api/index"; import { makeUrl } from "api/utils"; import { ChoicesSync } from "types/Choices"; import { EkklesiaChoiceParamsWithSubKey, + EkklesiaExtra, EkklesiaFields, EkklesiaParams, EkklesiaParentsChilds, EkklesiaResponse } from "types/Ekklesia"; import { t } from "utils/i18n"; -import { isObject } from "utils/reader/object"; -import { read as readString } from "utils/reader/string"; import { Literal } from "utils/types"; export const requestFields = (url: string): Promise => { @@ -28,12 +28,12 @@ export const keysHaveSubkey = ( export const getOption = ( obj: Record | undefined ): ChoicesSync => - isObject(obj) + Obj.isObject(obj) ? [ { title: t("None"), value: "" }, ...Object.entries(obj).map(([key, value]) => { return { - title: readString(value) ?? "", + title: Str.read(value) ?? "", value: key }; }) @@ -44,11 +44,12 @@ export const getFields = async < T extends keyof EkklesiaFields = keyof EkklesiaFields >( _url: string, - keys: EkklesiaParams + keys: EkklesiaParams, + extra?: EkklesiaExtra ): Promise => { const { key } = keys; - const url = makeUrl(_url, { module: key }); + const url = makeUrl(_url, { module: key, ...extra }); const { data = {} } = await requestFields(url); const field = data[key]; diff --git a/public/editor-client/src/types/Ekklesia.ts b/public/editor-client/src/types/Ekklesia.ts index c45a23f9ef..6ebc5fc731 100644 --- a/public/editor-client/src/types/Ekklesia.ts +++ b/public/editor-client/src/types/Ekklesia.ts @@ -18,6 +18,10 @@ export interface EkklesiaFields { smallgroupsLvl: EkklesiaParentsChilds; } +export interface EkklesiaExtra { + find_group?: string; +} + export interface EkklesiaParentsChilds { parents: Record; childs: Record;