Skip to content

Commit

Permalink
refactor: use react hook form for link create modal (#1545)
Browse files Browse the repository at this point in the history
* refactor: use react hook form for link create modal

* refactor: apply PR requested changes
  • Loading branch information
pyphilia authored Oct 25, 2024
1 parent d3bd11b commit 760b77a
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 197 deletions.
23 changes: 10 additions & 13 deletions src/components/item/form/link/LinkDescriptionField.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent } from 'react';
import { UseFormRegisterReturn } from 'react-hook-form';

import { IconButton, TextField } from '@mui/material';

Expand All @@ -8,36 +8,33 @@ import { useBuilderTranslation } from '@/config/i18n';
import { BUILDER } from '@/langs/constants';

type LinkDescriptionFieldProps = {
value: string | null | undefined;
onChange: (newValue: string) => void;
onRestore: () => void;
onClear: () => void;
showRestore: boolean;
showRestoreButton?: boolean;
form: UseFormRegisterReturn;
showClearButton?: boolean;
};
const LinkDescriptionField = ({
value,
onChange,
form,
onRestore,
onClear,
showRestore,
showRestoreButton,
showClearButton,
}: LinkDescriptionFieldProps): JSX.Element => {
const { t } = useBuilderTranslation();
return (
<TextField
label={t(BUILDER.DESCRIPTION_LABEL)}
variant="standard"
InputLabelProps={{ shrink: true }}
value={value}
onChange={({
target: { value: newValue },
}: ChangeEvent<HTMLInputElement>) => onChange(newValue)}
{...form}
InputProps={{
endAdornment: (
<>
<IconButton
onClick={onRestore}
sx={{
visibility: showRestore ? 'visible' : 'hidden',
visibility: showRestoreButton ? 'visible' : 'hidden',
}}
>
<Undo2Icon size="20" />
Expand All @@ -46,7 +43,7 @@ const LinkDescriptionField = ({
<IconButton
onClick={onClear}
sx={{
visibility: value ? 'visible' : 'hidden',
visibility: showClearButton ? 'visible' : 'hidden',
}}
>
<XIcon size="20" />
Expand Down
Loading

0 comments on commit 760b77a

Please sign in to comment.