This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#1122): fix types and make text editable
- Loading branch information
1 parent
bef4ece
commit ef9ee61
Showing
17 changed files
with
561 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Backend ORM/SQL Crate | ||
p# Backend ORM/SQL Crate | ||
|
||
## Problem | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
frontend/src/components/Form/DebouncedSimpleFormTextArea.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ComponentPropsWithoutRef } from 'react'; | ||
import { | ||
FieldValues, | ||
Path, | ||
SubmitErrorHandler, | ||
SubmitHandler, | ||
useFormContext, | ||
} from 'react-hook-form'; | ||
import { useDebouncedSubmit } from '@/hooks/useDebouncedSubmit'; | ||
import CheckIcon from '@/svg/icons/check.svg?react'; | ||
import CircleDottedIcon from '@/svg/icons/circle-dotted.svg?react'; | ||
import SimpleFormTextArea from './SimpleFormTextArea'; | ||
|
||
type DebouncedSimpleFormTextAreatProps<T extends FieldValues = FieldValues> = { | ||
/** A function that takes the from values. | ||
* It is called if the settled value of the input is valid */ | ||
onValid: SubmitHandler<T>; | ||
/** A function that takes the form error. | ||
* It is called if the settled value of the input is invalid */ | ||
onInvalid?: SubmitErrorHandler<T> | undefined; | ||
/** The elements unique id. | ||
* Gets passed to react-hook-form to identify which field the input belongs to. */ | ||
id: Path<T>; | ||
/** The test id for the input */ | ||
'data-testid'?: string; | ||
} & Omit<SimpleFormInputProps, 'aria-invalid' | 'id' | 'register'>; | ||
|
||
type SimpleFormInputProps = ComponentPropsWithoutRef<typeof SimpleFormTextArea>; | ||
|
||
export function DebouncedSimpleFormTextArea<T extends FieldValues>({ | ||
onValid, | ||
onInvalid, | ||
id, | ||
'data-testid': testId, | ||
...rest | ||
}: DebouncedSimpleFormTextAreatProps<T>) { | ||
const { handleSubmit, register, watch } = useFormContext<T>(); | ||
|
||
const submitState = useDebouncedSubmit<T>(watch(id), handleSubmit, onValid, onInvalid); | ||
|
||
return ( | ||
<div data-testid={testId} className="flex gap-2"> | ||
<SimpleFormTextArea {...{ id, register, ...rest }} aria-invalid={submitState === 'error'} /> | ||
{submitState === 'loading' && ( | ||
<CircleDottedIcon | ||
className="mb-3 mt-auto h-5 w-5 flex-shrink-0 animate-spin text-secondary-400" | ||
data-testid="form-input-loading" | ||
/> | ||
)} | ||
{submitState === 'idle' && ( | ||
<CheckIcon | ||
className="mb-3 mt-auto h-5 w-5 flex-shrink-0 text-primary-400" | ||
data-testid="form-input-idle" | ||
/> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.