All files / src/utils/dynamicAlerts constructTaskBuilder.ts

0% Statements 0/16
0% Branches 0/2
0% Functions 0/6
0% Lines 0/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                                     
import { HandleInputRenderType } from "../../components/Inputs/HandleInputRender";
import { store } from "../../store";
import { commonKeySelector } from "../../store/features/common/selectors";
import { FormFields } from "../../types/inputs/formFields";
import handleInputType from "../playbook/handleInputType";
 
const fieldToInput = (field: FormFields): HandleInputRenderType => {
  return {
    key: field.key_name,
    label: field.display_name,
    placeholder: field.description,
    options: field.valid_values?.map((v) => ({
      id: v[v.type.toLowerCase()],
      label: v[v.type.toLowerCase()],
    })),
    inputType: field.form_field_type,
    type: handleInputType(field.data_type),
    isOptional: field.is_optional,
    default: field.default_value?.[field.default_value.type.toLowerCase()],
    compositeFields: field.composite_fields?.map((f) => fieldToInput(f)),
    value: undefined,
  };
};
 
export const constructBuilder = () => {
  const { supportedTaskTypes } = commonKeySelector(store.getState());
  const source = "";
  const taskType = "";
  const type = supportedTaskTypes?.find(
    (e: any) => e.source === source.toUpperCase() && e.task_type === taskType,
  );
 
  return type?.form_fields.map((field: FormFields) => fieldToInput(field));
};