apps/meteor/client/views/admin/settings/Setting/inputs/RelativeUrlSettingInput.tsx
import { Field, FieldLabel, FieldRow, UrlInput } from '@rocket.chat/fuselage';
import { useAbsoluteUrl } from '@rocket.chat/ui-contexts';
import type { EventHandler, ReactElement, SyntheticEvent } from 'react';
import React from 'react';
import ResetSettingButton from '../ResetSettingButton';
import type { SettingInputProps } from './types';
type RelativeUrlSettingInputProps = SettingInputProps;
function RelativeUrlSettingInput({
_id,
label,
value,
placeholder,
readonly,
autocomplete,
disabled,
required,
hasResetButton,
onChangeValue,
onResetButtonClick,
}: RelativeUrlSettingInputProps): ReactElement {
const getAbsoluteUrl = useAbsoluteUrl();
const handleChange: EventHandler<SyntheticEvent<HTMLInputElement>> = (event) => {
onChangeValue?.(event.currentTarget.value);
};
return (
<Field>
<FieldRow>
<FieldLabel htmlFor={_id} title={_id} required={required}>
{label}
</FieldLabel>
{hasResetButton && <ResetSettingButton data-qa-reset-setting-id={_id} onClick={onResetButtonClick} />}
</FieldRow>
<UrlInput
data-qa-setting-id={_id}
id={_id}
value={getAbsoluteUrl(value || '')}
placeholder={placeholder}
disabled={disabled}
readOnly={readonly}
autoComplete={autocomplete === false ? 'off' : undefined}
onChange={handleChange}
/>
</Field>
);
}
export default RelativeUrlSettingInput;