2023-02-19 09:53:57 +01:00
|
|
|
import { FormLabel, HStack, Stack, Text } from '@chakra-ui/react'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { CodeEditor } from '@/components/CodeEditor'
|
2022-06-12 17:34:33 +02:00
|
|
|
import { FileInputOptions, Variable } from 'models'
|
|
|
|
import React from 'react'
|
2022-11-15 09:35:48 +01:00
|
|
|
import { Input, SmartNumberInput } from '@/components/inputs'
|
|
|
|
import { SwitchWithLabel } from '@/components/SwitchWithLabel'
|
|
|
|
import { VariableSearchInput } from '@/components/VariableSearchInput'
|
2022-06-12 17:34:33 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
options: FileInputOptions
|
|
|
|
onOptionsChange: (options: FileInputOptions) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FileInputSettings = ({ options, onOptionsChange }: Props) => {
|
|
|
|
const handleButtonLabelChange = (button: string) =>
|
|
|
|
onOptionsChange({ ...options, labels: { ...options.labels, button } })
|
2023-01-20 08:12:59 +01:00
|
|
|
|
2022-06-12 17:34:33 +02:00
|
|
|
const handlePlaceholderLabelChange = (placeholder: string) =>
|
|
|
|
onOptionsChange({ ...options, labels: { ...options.labels, placeholder } })
|
2023-01-20 08:12:59 +01:00
|
|
|
|
2022-06-25 09:24:47 +02:00
|
|
|
const handleMultipleFilesChange = (isMultipleAllowed: boolean) =>
|
2022-06-12 17:34:33 +02:00
|
|
|
onOptionsChange({ ...options, isMultipleAllowed })
|
2023-01-20 08:12:59 +01:00
|
|
|
|
2022-06-12 17:34:33 +02:00
|
|
|
const handleVariableChange = (variable?: Variable) =>
|
|
|
|
onOptionsChange({ ...options, variableId: variable?.id })
|
2023-01-20 08:12:59 +01:00
|
|
|
|
2022-06-21 16:53:45 +02:00
|
|
|
const handleSizeLimitChange = (sizeLimit?: number) =>
|
|
|
|
onOptionsChange({ ...options, sizeLimit })
|
2023-01-20 08:12:59 +01:00
|
|
|
|
2022-06-25 09:24:47 +02:00
|
|
|
const handleRequiredChange = (isRequired: boolean) =>
|
|
|
|
onOptionsChange({ ...options, isRequired })
|
2023-01-20 08:12:59 +01:00
|
|
|
|
|
|
|
const updateClearButtonLabel = (clear: string) =>
|
|
|
|
onOptionsChange({ ...options, labels: { ...options.labels, clear } })
|
|
|
|
|
|
|
|
const updateSkipButtonLabel = (skip: string) =>
|
|
|
|
onOptionsChange({ ...options, labels: { ...options.labels, skip } })
|
|
|
|
|
2022-06-12 17:34:33 +02:00
|
|
|
return (
|
|
|
|
<Stack spacing={4}>
|
2022-06-25 09:24:47 +02:00
|
|
|
<SwitchWithLabel
|
|
|
|
label="Required?"
|
|
|
|
initialValue={options.isRequired ?? true}
|
|
|
|
onCheckChange={handleRequiredChange}
|
|
|
|
/>
|
2022-06-12 17:34:33 +02:00
|
|
|
<SwitchWithLabel
|
|
|
|
label="Allow multiple files?"
|
|
|
|
initialValue={options.isMultipleAllowed}
|
2022-06-25 09:24:47 +02:00
|
|
|
onCheckChange={handleMultipleFilesChange}
|
2022-06-12 17:34:33 +02:00
|
|
|
/>
|
2023-02-19 09:53:57 +01:00
|
|
|
<HStack>
|
2022-06-21 16:53:45 +02:00
|
|
|
<SmartNumberInput
|
2023-02-19 09:53:57 +01:00
|
|
|
label={'Size limit:'}
|
|
|
|
defaultValue={options.sizeLimit ?? 10}
|
2022-06-21 16:53:45 +02:00
|
|
|
onValueChange={handleSizeLimitChange}
|
2023-02-19 09:53:57 +01:00
|
|
|
withVariableButton={false}
|
2022-06-21 16:53:45 +02:00
|
|
|
/>
|
2023-02-19 09:53:57 +01:00
|
|
|
<Text>MB</Text>
|
|
|
|
</HStack>
|
|
|
|
|
2022-06-12 17:34:33 +02:00
|
|
|
<Stack>
|
|
|
|
<FormLabel mb="0">Placeholder:</FormLabel>
|
|
|
|
<CodeEditor
|
|
|
|
lang="html"
|
|
|
|
onChange={handlePlaceholderLabelChange}
|
2023-02-21 15:25:14 +01:00
|
|
|
defaultValue={options.labels.placeholder}
|
2022-06-12 17:34:33 +02:00
|
|
|
height={'100px'}
|
|
|
|
withVariableButton={false}
|
|
|
|
/>
|
|
|
|
</Stack>
|
2023-01-20 08:12:59 +01:00
|
|
|
<Input
|
|
|
|
label="Button label:"
|
|
|
|
defaultValue={options.labels.button}
|
|
|
|
onChange={handleButtonLabelChange}
|
|
|
|
withVariableButton={false}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
label="Clear button label:"
|
|
|
|
defaultValue={options.labels.clear}
|
|
|
|
onChange={updateClearButtonLabel}
|
|
|
|
withVariableButton={false}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
label="Skip button label:"
|
|
|
|
defaultValue={options.labels.skip}
|
|
|
|
onChange={updateSkipButtonLabel}
|
|
|
|
withVariableButton={false}
|
|
|
|
/>
|
2022-06-12 17:34:33 +02:00
|
|
|
<Stack>
|
|
|
|
<FormLabel mb="0" htmlFor="variable">
|
|
|
|
Save upload URL{options.isMultipleAllowed ? 's' : ''} in a variable:
|
|
|
|
</FormLabel>
|
|
|
|
<VariableSearchInput
|
|
|
|
initialVariableId={options.variableId}
|
|
|
|
onSelectVariable={handleVariableChange}
|
|
|
|
/>
|
|
|
|
</Stack>
|
|
|
|
</Stack>
|
|
|
|
)
|
|
|
|
}
|