-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into client-3912-calendar
- Loading branch information
Showing
14 changed files
with
382 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/topLevelPages/myDashboard/newVirtualContributorWizard/CreateExternalAIDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React from 'react'; | ||
import { Form, Formik } from 'formik'; | ||
import * as yup from 'yup'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { DialogContent } from '@mui/material'; | ||
import DialogHeader from '../../../../core/ui/dialog/DialogHeader'; | ||
import Gutters from '../../../../core/ui/grid/Gutters'; | ||
import { Caption } from '../../../../core/ui/typography'; | ||
import { Actions } from '../../../../core/ui/actions/Actions'; | ||
import FormikInputField from '../../../../core/ui/forms/FormikInputField/FormikInputField'; | ||
import LoadingButton from '@mui/lab/LoadingButton'; | ||
import { AiPersonaEngine } from '../../../../core/apollo/generated/graphql-schema'; | ||
import ExternalAIComingSoonDialog from './ExternalAIComingSoonDialog'; | ||
import FormikAutocomplete from '../../../../core/ui/forms/FormikAutocomplete'; | ||
|
||
const PROVIDERS = [ | ||
{ id: AiPersonaEngine.OpenaiAssistant, name: 'OpenAI Assistant' }, | ||
{ id: AiPersonaEngine.GenericOpenai, name: 'OpenAI' }, | ||
]; | ||
|
||
interface CreateExternalAIDialogProps { | ||
onClose: () => void; | ||
onCreateExternal: (externalparams: ExternalVcFormValues) => void; | ||
} | ||
|
||
export interface ExternalVcFormValues { | ||
engine: AiPersonaEngine; | ||
apiKey: string; | ||
assistantId?: string; | ||
} | ||
|
||
const CreateExternalAIDialog: React.FC<CreateExternalAIDialogProps> = ({ onClose, onCreateExternal }) => { | ||
const { t } = useTranslation(); | ||
|
||
const initialValues: ExternalVcFormValues = { | ||
engine: AiPersonaEngine.GenericOpenai, | ||
apiKey: '', | ||
assistantId: '', | ||
}; | ||
|
||
const validationSchema = yup.object().shape({ | ||
engine: yup | ||
.string() | ||
.oneOf(PROVIDERS.map(({ id }) => id)) | ||
.required(), | ||
apiKey: yup.string().required(), | ||
assistantId: yup.string().when('engine', { | ||
is: AiPersonaEngine.OpenaiAssistant, | ||
then: yup.string().required(), | ||
otherwise: yup.string().notRequired(), | ||
}), | ||
}); | ||
|
||
const handleSubmit = async (values: ExternalVcFormValues) => { | ||
onCreateExternal(values); | ||
}; | ||
|
||
return ( | ||
<Formik | ||
initialValues={initialValues} | ||
validationSchema={validationSchema} | ||
enableReinitialize | ||
validateOnMount | ||
onSubmit={(values: ExternalVcFormValues) => handleSubmit(values)} | ||
> | ||
{({ isValid, handleChange, values }) => ( | ||
<> | ||
<DialogHeader title={t('createVirtualContributorWizard.externalAI.create.title')} onClose={onClose} /> | ||
<DialogContent sx={{ paddingTop: 0 }}> | ||
<Caption alignSelf="center">{t('createVirtualContributorWizard.externalAI.create.subTitle')}</Caption> | ||
|
||
<Form> | ||
<Gutters disablePadding sx={{ paddingTop: 2, paddingBottom: 2 }}> | ||
<FormikAutocomplete | ||
name="engine" | ||
label={t('createVirtualContributorWizard.externalAI.create.provider.title')} | ||
title="title" | ||
placeholder={t('createVirtualContributorWizard.externalAI.create.provider.placeholder')} | ||
values={PROVIDERS} | ||
/> | ||
<FormikInputField | ||
name="apiKey" | ||
title={t('createVirtualContributorWizard.externalAI.create.apiKey.label')} | ||
placeholder={t('createVirtualContributorWizard.externalAI.create.apiKey.placeholder')} | ||
onChange={handleChange} | ||
/> | ||
{values.engine === AiPersonaEngine.OpenaiAssistant && ( | ||
<FormikInputField | ||
name="assistantId" | ||
title={t('createVirtualContributorWizard.externalAI.create.assistantId.label')} | ||
placeholder={t('createVirtualContributorWizard.externalAI.create.assistantId.placeholder')} | ||
onChange={handleChange} | ||
/> | ||
)} | ||
<Actions justifyContent="end"> | ||
<LoadingButton variant="contained" disabled={!isValid} type="submit"> | ||
{t('buttons.create')} | ||
</LoadingButton> | ||
</Actions> | ||
</Gutters> | ||
</Form> | ||
<ExternalAIComingSoonDialog onClose={onClose} /> | ||
</DialogContent> | ||
</> | ||
)} | ||
</Formik> | ||
); | ||
}; | ||
|
||
export default CreateExternalAIDialog; |
Oops, something went wrong.