Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.4 KB
Raw Blame
import { isNil } from '@activepieces/core-utils';
import { t } from 'i18next';
import { Control } from 'react-hook-form';

import {
  getProjectName,
  projectCollectionUtils,
} from '@/features/projects/stores/project-collection';

import { MultiSelectPieceProperty } from '../../../components/custom/multi-select-piece-property';
import { FormField, FormItem, FormMessage } from '../../../components/ui/form';
import { Label } from '../../../components/ui/label';

export const ProjectSelector = ({
  control,
  name,
}: {
  control: Control<any>;
  name: string;
}) => {
  const { data: projects } = projectCollectionUtils.useAll();
  return (
    <FormField
      control={control}
      name={name}
      render={({ field }) => (
        <FormItem className="flex flex-col gap-2">
          <Label>{t('Available for Projects')}</Label>
          <MultiSelectPieceProperty
            placeholder={t('Select projects')}
            options={
              projects?.map((project) => ({
                value: project.id,
                label: getProjectName(project),
              })) ?? []
            }
            loading={!projects}
            onChange={(value) => {
              field.onChange(isNil(value) ? [] : value);
            }}
            initialValues={field.value}
            showDeselect={field.value.length > 0}
          />

          <FormMessage />
        </FormItem>
      )}
    />
  );
};