-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
663 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import clsx from 'clsx'; | ||
|
||
export type TextAreaProps = JSX.IntrinsicElements['textarea']; | ||
|
||
export function TextArea({ className, ...props }: TextAreaProps) { | ||
return ( | ||
<textarea | ||
{...props} | ||
className={clsx('uk-textarea', className)} | ||
/> | ||
); | ||
} |
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
75 changes: 75 additions & 0 deletions
75
apps/admin/src/modules/apps/form/create/app-create-form-modal.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,75 @@ | ||
import type { SdkCreateAppInputT } from '@llm/sdk'; | ||
|
||
import { | ||
CancelButton, | ||
CreateButton, | ||
FormErrorAlert, | ||
FormField, | ||
Modal, | ||
type ModalProps, | ||
ModalTitle, | ||
} from '~/components'; | ||
import { useI18n } from '~/i18n'; | ||
import { OrganizationsSearchSelect } from '~/modules/organizations/controls/organizations-search-select'; | ||
|
||
import { AppSharedFormFields } from '../shared'; | ||
import { useAppCreateForm } from './use-app-create-form'; | ||
|
||
export type AppCreateFormModalProps = | ||
& Omit<ModalProps, 'children' | 'header' | 'formProps'> | ||
& { | ||
defaultValue: SdkCreateAppInputT; | ||
onAfterSubmit?: VoidFunction; | ||
}; | ||
|
||
export function AppCreateFormModal( | ||
{ | ||
defaultValue, | ||
onAfterSubmit, | ||
onClose, | ||
...props | ||
}: AppCreateFormModalProps, | ||
) { | ||
const t = useI18n().pack.modules.apps.form; | ||
const { handleSubmitEvent, validator, submitState, bind } = useAppCreateForm({ | ||
defaultValue, | ||
onAfterSubmit, | ||
}); | ||
|
||
return ( | ||
<Modal | ||
{...props} | ||
isOverflowVisible | ||
onClose={onClose} | ||
formProps={{ | ||
onSubmit: handleSubmitEvent, | ||
}} | ||
header={( | ||
<ModalTitle> | ||
{t.title.create} | ||
</ModalTitle> | ||
)} | ||
footer={( | ||
<> | ||
<CancelButton disabled={submitState.loading} onClick={onClose} /> | ||
<CreateButton loading={submitState.loading} type="submit" /> | ||
</> | ||
)} | ||
> | ||
<FormField | ||
className="uk-margin" | ||
label={t.fields.organization.label} | ||
{...validator.errors.extract('organization')} | ||
> | ||
<OrganizationsSearchSelect {...bind.path('organization')} required /> | ||
</FormField> | ||
|
||
<AppSharedFormFields | ||
errors={validator.errors.all as any} | ||
{...bind.merged()} | ||
/> | ||
|
||
<FormErrorAlert result={submitState.result} /> | ||
</Modal> | ||
); | ||
} |
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,3 @@ | ||
export * from './app-create-form-modal'; | ||
export * from './use-app-create-form'; | ||
export * from './use-app-create-modal'; |
46 changes: 46 additions & 0 deletions
46
apps/admin/src/modules/apps/form/create/use-app-create-form.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,46 @@ | ||
import { type FormHookAttrs, useForm } from '@under-control/forms'; | ||
import { flow } from 'fp-ts/lib/function'; | ||
|
||
import { runTask, tapTaskEither } from '@llm/commons'; | ||
import { type SdkCreateAppInputT, useSdkForLoggedIn } from '@llm/sdk'; | ||
import { useSaveTaskEitherNotification } from '~/components'; | ||
import { usePredefinedFormValidators } from '~/hooks'; | ||
|
||
type CreateAppFormHookAttrs = | ||
& Omit< | ||
FormHookAttrs<SdkCreateAppInputT>, | ||
'validation' | 'onSubmit' | ||
> | ||
& { | ||
onAfterSubmit?: VoidFunction; | ||
}; | ||
|
||
export function useAppCreateForm( | ||
{ | ||
onAfterSubmit, | ||
...props | ||
}: CreateAppFormHookAttrs, | ||
) { | ||
const { sdks } = useSdkForLoggedIn(); | ||
const { required, requiredListItem } = usePredefinedFormValidators<SdkCreateAppInputT>(); | ||
const saveNotifications = useSaveTaskEitherNotification(); | ||
|
||
return useForm({ | ||
resetAfterSubmit: false, | ||
onSubmit: flow( | ||
sdks.dashboard.apps.create, | ||
saveNotifications, | ||
tapTaskEither(() => onAfterSubmit?.()), | ||
runTask, | ||
), | ||
validation: { | ||
mode: ['blur', 'submit'], | ||
validators: () => [ | ||
required('name'), | ||
required('chatContext'), | ||
requiredListItem('organization'), | ||
], | ||
}, | ||
...props, | ||
}); | ||
} |
32 changes: 32 additions & 0 deletions
32
apps/admin/src/modules/apps/form/create/use-app-create-modal.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,32 @@ | ||
import type { SdkCreateAppInputT } from '@llm/sdk'; | ||
|
||
import { useAnimatedModal } from '@llm/commons-front'; | ||
|
||
import { | ||
AppCreateFormModal, | ||
type AppCreateFormModalProps, | ||
} from './app-create-form-modal'; | ||
|
||
type AppShowModalProps = | ||
& Pick<AppCreateFormModalProps, 'onAfterSubmit'> | ||
& { | ||
defaultValue: SdkCreateAppInputT; | ||
}; | ||
|
||
export function useAppCreateModal() { | ||
return useAnimatedModal<boolean, AppShowModalProps>({ | ||
renderModalContent: ({ showProps, hiding, onAnimatedClose }) => ( | ||
<AppCreateFormModal | ||
{...showProps} | ||
isLeaving={hiding} | ||
onAfterSubmit={() => { | ||
void onAnimatedClose(true); | ||
showProps?.onAfterSubmit?.(); | ||
}} | ||
onClose={() => { | ||
void onAnimatedClose(); | ||
}} | ||
/> | ||
), | ||
}); | ||
} |
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,2 @@ | ||
export * from './create'; | ||
export * from './update'; |
46 changes: 46 additions & 0 deletions
46
apps/admin/src/modules/apps/form/shared/app-shared-form-fields.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,46 @@ | ||
import { controlled, useFormValidatorMessages, type ValidationErrorsListProps } from '@under-control/forms'; | ||
|
||
import type { SdkAppT } from '@llm/sdk'; | ||
|
||
import { FormField, Input, TextArea } from '~/components'; | ||
import { useI18n } from '~/i18n'; | ||
|
||
type Value = Pick<SdkAppT, 'name' | 'chatContext'>; | ||
|
||
type Props = ValidationErrorsListProps<Value>; | ||
|
||
export const AppSharedFormFields = controlled<Value, Props>(({ errors, control: { bind } }) => { | ||
const t = useI18n().pack.modules.apps.form; | ||
const validation = useFormValidatorMessages({ errors }); | ||
|
||
return ( | ||
<> | ||
<FormField | ||
className="uk-margin" | ||
label={t.fields.name.label} | ||
{...validation.extract('name')} | ||
> | ||
<Input | ||
name="name" | ||
placeholder={t.fields.name.placeholder} | ||
required | ||
{...bind.path('name')} | ||
/> | ||
</FormField> | ||
|
||
<FormField | ||
className="uk-margin" | ||
label={t.fields.chatContext.label} | ||
{...validation.extract('name')} | ||
> | ||
<TextArea | ||
name="chat-context" | ||
placeholder={t.fields.chatContext.placeholder} | ||
rows={3} | ||
required | ||
{...bind.path('chatContext')} | ||
/> | ||
</FormField> | ||
</> | ||
); | ||
}); |
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 @@ | ||
export * from './app-shared-form-fields'; |
Oops, something went wrong.