2023-07-10 15:56:12 +00:00
|
|
|
import { Database, Globe } from 'lucide-react';
|
2023-10-19 11:45:50 +00:00
|
|
|
import { FormikErrors } from 'formik';
|
2023-07-10 15:56:12 +00:00
|
|
|
import { PropsWithChildren } from 'react';
|
|
|
|
|
|
|
|
import { Button } from '@@/buttons';
|
|
|
|
|
|
|
|
import { SimpleForm } from './SimpleForm';
|
|
|
|
import { Values } from './types';
|
|
|
|
import { AdvancedForm } from './AdvancedForm';
|
|
|
|
import { RateLimits } from './RateLimits';
|
|
|
|
|
|
|
|
export function ImageConfigFieldset({
|
2023-10-19 11:45:50 +00:00
|
|
|
onRateLimit,
|
2023-07-10 15:56:12 +00:00
|
|
|
children,
|
|
|
|
autoComplete,
|
|
|
|
values,
|
|
|
|
errors,
|
2023-10-19 11:45:50 +00:00
|
|
|
onChangeImage,
|
|
|
|
setFieldValue,
|
2023-07-10 15:56:12 +00:00
|
|
|
}: PropsWithChildren<{
|
|
|
|
values: Values;
|
|
|
|
errors?: FormikErrors<Values>;
|
|
|
|
autoComplete?: boolean;
|
2023-10-19 11:45:50 +00:00
|
|
|
onRateLimit?: (limited?: boolean) => void;
|
|
|
|
onChangeImage?: (name: string) => void;
|
|
|
|
setFieldValue: <T>(field: string, value: T) => void;
|
2023-07-10 15:56:12 +00:00
|
|
|
}>) {
|
|
|
|
const Component = values.useRegistry ? SimpleForm : AdvancedForm;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="row">
|
|
|
|
<Component
|
|
|
|
autoComplete={autoComplete}
|
|
|
|
values={values}
|
|
|
|
errors={errors}
|
2023-10-19 11:45:50 +00:00
|
|
|
onChangeImage={onChangeImage}
|
|
|
|
setFieldValue={setFieldValue}
|
2023-07-10 15:56:12 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<div className="form-group">
|
|
|
|
<div className="col-sm-12">
|
|
|
|
{values.useRegistry ? (
|
|
|
|
<Button
|
|
|
|
size="small"
|
|
|
|
color="link"
|
|
|
|
icon={Globe}
|
|
|
|
className="!ml-0 p-0 hover:no-underline"
|
2023-10-19 11:45:50 +00:00
|
|
|
onClick={() => setFieldValue('useRegistry', false)}
|
2023-07-10 15:56:12 +00:00
|
|
|
>
|
|
|
|
Advanced mode
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<Button
|
|
|
|
size="small"
|
|
|
|
color="link"
|
|
|
|
icon={Database}
|
|
|
|
className="!ml-0 p-0 hover:no-underline"
|
2023-10-19 11:45:50 +00:00
|
|
|
onClick={() => setFieldValue('useRegistry', true)}
|
2023-07-10 15:56:12 +00:00
|
|
|
>
|
|
|
|
Simple mode
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{children}
|
|
|
|
|
2023-10-19 11:45:50 +00:00
|
|
|
{onRateLimit && values.useRegistry && (
|
|
|
|
<RateLimits registryId={values.registryId} onRateLimit={onRateLimit} />
|
2023-07-10 15:56:12 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|