mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-05 20:28:23 +00:00
98 lines
2.7 KiB
TypeScript
98 lines
2.7 KiB
TypeScript
import type { Dispatch, SetStateAction } from 'react';
|
|
import type {
|
|
CreateUpstreamProvider,
|
|
ProviderType,
|
|
} from '@/lib/api/services/admin';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
import { ProviderFormFields } from '@/components/provider-form-fields';
|
|
import { ppqAutoTopupSettingsInvalid } from '@/components/providers/PPQAutoTopupSettings';
|
|
|
|
interface ProviderFormDialogContentProps {
|
|
mode: 'create' | 'edit';
|
|
title: string;
|
|
description: string;
|
|
submitLabel: string;
|
|
submittingLabel: string;
|
|
formData: CreateUpstreamProvider;
|
|
setFormData: Dispatch<SetStateAction<CreateUpstreamProvider>>;
|
|
providerTypes: ProviderType[];
|
|
providerFeePlaceholder: string;
|
|
docsLinkClassName: string;
|
|
canCreateAccount: boolean;
|
|
isCreatingAccount: boolean;
|
|
onCreateAccount: () => void;
|
|
onCancel: () => void;
|
|
onSubmit: () => void;
|
|
isSubmitting: boolean;
|
|
availableMints: string[];
|
|
}
|
|
|
|
export function ProviderFormDialogContent({
|
|
mode,
|
|
title,
|
|
description,
|
|
submitLabel,
|
|
submittingLabel,
|
|
formData,
|
|
setFormData,
|
|
providerTypes,
|
|
providerFeePlaceholder,
|
|
docsLinkClassName,
|
|
canCreateAccount,
|
|
isCreatingAccount,
|
|
onCreateAccount,
|
|
onCancel,
|
|
onSubmit,
|
|
isSubmitting,
|
|
availableMints,
|
|
}: ProviderFormDialogContentProps) {
|
|
// The server re-validates these bounds; this only stops submitting a form
|
|
// whose inline errors are already visible.
|
|
const hasInvalidSettings =
|
|
formData.provider_type === 'ppqai' &&
|
|
ppqAutoTopupSettingsInvalid(formData.provider_settings || {});
|
|
return (
|
|
<DialogContent className='max-h-[90dvh] overflow-y-auto sm:max-w-[500px]'>
|
|
<DialogHeader>
|
|
<DialogTitle>{title}</DialogTitle>
|
|
<DialogDescription>{description}</DialogDescription>
|
|
</DialogHeader>
|
|
<ProviderFormFields
|
|
mode={mode}
|
|
formData={formData}
|
|
setFormData={setFormData}
|
|
providerTypes={providerTypes}
|
|
providerFeePlaceholder={providerFeePlaceholder}
|
|
docsLinkClassName={docsLinkClassName}
|
|
canCreateAccount={canCreateAccount}
|
|
isCreatingAccount={isCreatingAccount}
|
|
onCreateAccount={onCreateAccount}
|
|
availableMints={availableMints}
|
|
/>
|
|
<DialogFooter>
|
|
<Button
|
|
variant='outline'
|
|
onClick={onCancel}
|
|
className='w-full sm:w-auto'
|
|
>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
onClick={onSubmit}
|
|
disabled={isSubmitting || hasInvalidSettings}
|
|
className='w-full sm:w-auto'
|
|
>
|
|
{isSubmitting ? submittingLabel : submitLabel}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
);
|
|
}
|