Files
calendar/packages/app-store/routing-forms/lib/findFieldValueByIdentifier.ts
T
Benny JooandGitHub d908403a99 refactor: circular deps between app store and lib [1] (#23653)
* move dailyApiFetcher.ts to app store package

* update imports

* bookingLocationService

* revert

* move findFieldValueByIdentifier

* wip

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* move to features package

* update imports

* update imports

* move

* fix typechecks

* move getCalendarLinks

* mv event test
2025-09-09 14:38:29 +00:00

21 lines
709 B
TypeScript

import getFieldIdentifier from "./getFieldIdentifier";
import type { RoutingFormResponseData } from "./responseData/types";
type FindFieldValueByIdentifierResult =
| { success: true; data: string | string[] | number | null }
| { success: false; error: string };
export function findFieldValueByIdentifier(
data: RoutingFormResponseData,
identifier: string
): FindFieldValueByIdentifierResult {
const field = data.fields.find((field) => getFieldIdentifier(field) === identifier);
if (!field) {
return { success: false, error: `Field with identifier ${identifier} not found` };
}
const fieldValue = data.response[field.id]?.value;
return { success: true, data: fieldValue ?? null };
}