create.config.ts 7.38 KB
import {
  PerimeterTypeEnum,
  RangeUtilEnum,
  RangeUtilNameEnum,
  TimeIntervalUnitEnum,
  TimeIntervalUnitNameEnum,
} from '../../../enum/form';
import { useRuleChainI18n } from '../../../hook/useRuleChainI18n';
import { FormSchema } from '/@/components/Form';

// Gps geofencing events
export enum GpsGeofencingEventsFieldsEnum {
  LATITUDE_KEY_NAME = 'latitudeKeyName',
  LONGITUDE_KEY_NAME = 'longitudeKeyName',
  PERIMETER_TYPE = 'perimeterType',
  FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA = 'fetchPerimeterInfoFromMessageMetadata',
  PERIMETER_KEY_NAME = 'perimeterKeyName',
  CENTER_LATITUDE = 'centerLatitude',
  CENTER_LONGITUDE = 'centerLongitude',
  RANGE = 'range',
  RANGE_UNIT = 'rangeUnit',
  POLYGONS_DEFINITION = 'polygonsDefinition',
  MIN_INSIDE_DURATION = 'minInsideDuration',
  MIN_INSIDE_DURATION_TIME_UNIT = 'minInsideDurationTimeUnit',
  MIN_OUTSIDE_DURATION = 'minOutsideDuration',
  MIN_OUTSIDE_DURATION_TIME_UNIT = 'minOutsideDurationTimeUnit',
}
const { tLabel, tPlaceholder } = useRuleChainI18n('action', 'gpsGeofencingEvents');

export const formSchemas: FormSchema[] = [
  {
    field: GpsGeofencingEventsFieldsEnum.LATITUDE_KEY_NAME,
    component: 'Input',
    label: tLabel(GpsGeofencingEventsFieldsEnum.LATITUDE_KEY_NAME),
    required: true,
    componentProps: {
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.LATITUDE_KEY_NAME),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.LONGITUDE_KEY_NAME,
    component: 'Input',
    label: tLabel(GpsGeofencingEventsFieldsEnum.LONGITUDE_KEY_NAME),
    required: true,
    componentProps: {
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.LONGITUDE_KEY_NAME),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE,
    component: 'Select',
    label: tLabel(GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE),
    required: true,
    componentProps: {
      options: Object.keys(PerimeterTypeEnum).map((value) => ({ label: value, value })),
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE, 'choose'),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA,
    component: 'Checkbox',
    label: '',
    renderComponentContent: () => ({
      default: () =>
        tLabel(GpsGeofencingEventsFieldsEnum.FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA),
    }),
  },
  {
    field: GpsGeofencingEventsFieldsEnum.PERIMETER_KEY_NAME,
    component: 'Input',
    label: tLabel(GpsGeofencingEventsFieldsEnum.PERIMETER_KEY_NAME),
    ifShow: ({ model }) =>
      model[GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE] === PerimeterTypeEnum.POLYGON &&
      model[GpsGeofencingEventsFieldsEnum.FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA],
    required: true,
    componentProps: {
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.PERIMETER_KEY_NAME),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.POLYGONS_DEFINITION,
    component: 'Input',
    label: tLabel(GpsGeofencingEventsFieldsEnum.POLYGONS_DEFINITION),
    helpMessage:
      'Please, use the following format for manual definition of polygon: [[lat1,lon1],[lat2,lon2], ... ,[latN,lonN]].',
    ifShow: ({ model }) =>
      model[GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE] === PerimeterTypeEnum.POLYGON &&
      !model[GpsGeofencingEventsFieldsEnum.FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA],
    required: true,
    componentProps: {
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.POLYGONS_DEFINITION),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.CENTER_LATITUDE,
    component: 'InputNumber',
    label: tLabel(GpsGeofencingEventsFieldsEnum.CENTER_LATITUDE),
    colProps: { span: 12 },
    ifShow: ({ model }) =>
      model[GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE] === PerimeterTypeEnum.CIRCLE &&
      !model[GpsGeofencingEventsFieldsEnum.FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA],
    required: true,
    componentProps: {
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.CENTER_LATITUDE),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.CENTER_LONGITUDE,
    component: 'InputNumber',
    label: tLabel(GpsGeofencingEventsFieldsEnum.CENTER_LONGITUDE),
    colProps: { span: 12 },
    ifShow: ({ model }) =>
      model[GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE] === PerimeterTypeEnum.CIRCLE &&
      !model[GpsGeofencingEventsFieldsEnum.FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA],
    componentProps: {
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.CENTER_LONGITUDE),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.RANGE,
    component: 'InputNumber',
    label: tLabel(GpsGeofencingEventsFieldsEnum.RANGE),
    colProps: { span: 12 },
    ifShow: ({ model }) =>
      model[GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE] === PerimeterTypeEnum.CIRCLE &&
      !model[GpsGeofencingEventsFieldsEnum.FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA],
    required: true,
    componentProps: {
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.RANGE),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.RANGE_UNIT,
    component: 'Select',
    label: tLabel(GpsGeofencingEventsFieldsEnum.RANGE_UNIT),
    colProps: { span: 12 },
    ifShow: ({ model }) =>
      model[GpsGeofencingEventsFieldsEnum.PERIMETER_TYPE] === PerimeterTypeEnum.CIRCLE &&
      !model[GpsGeofencingEventsFieldsEnum.FETCH_PERIMETER_INFO_FROM_MESSAGE_METADATA],
    required: true,
    componentProps: {
      options: Object.keys(RangeUtilEnum).map((value) => ({
        label: RangeUtilNameEnum[value],
        value,
      })),
      getPopupContainer: () => document.body,
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.RANGE_UNIT, 'choose'),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.MIN_INSIDE_DURATION,
    component: 'InputNumber',
    label: tLabel(GpsGeofencingEventsFieldsEnum.MIN_INSIDE_DURATION),
    colProps: { span: 12 },
    required: true,
    componentProps: {
      min: 1,
      max: 2147483647,
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.MIN_INSIDE_DURATION),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.MIN_INSIDE_DURATION_TIME_UNIT,
    component: 'Select',
    label: tLabel(GpsGeofencingEventsFieldsEnum.MIN_INSIDE_DURATION_TIME_UNIT),
    colProps: { span: 12 },
    required: true,
    componentProps: {
      options: Object.keys(TimeIntervalUnitEnum).map((value) => ({
        label: TimeIntervalUnitNameEnum[value],
        value,
      })),
      getPopupContainer: () => document.body,
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.MIN_INSIDE_DURATION_TIME_UNIT),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.MIN_OUTSIDE_DURATION,
    component: 'InputNumber',
    label: tLabel(GpsGeofencingEventsFieldsEnum.MIN_OUTSIDE_DURATION),
    colProps: { span: 12 },
    required: true,
    componentProps: {
      min: 1,
      max: 2147483647,
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.MIN_OUTSIDE_DURATION),
    },
  },
  {
    field: GpsGeofencingEventsFieldsEnum.MIN_OUTSIDE_DURATION_TIME_UNIT,
    component: 'Select',
    label: tLabel(GpsGeofencingEventsFieldsEnum.MIN_OUTSIDE_DURATION_TIME_UNIT),
    colProps: { span: 12 },
    required: true,
    componentProps: {
      options: Object.keys(TimeIntervalUnitEnum).map((value) => ({
        label: TimeIntervalUnitNameEnum[value],
        value,
      })),
      getPopupContainer: () => document.body,
      placeholder: tPlaceholder(GpsGeofencingEventsFieldsEnum.MIN_OUTSIDE_DURATION_TIME_UNIT),
    },
  },
];