mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added note dropping and editing
This commit is contained in:
parent
cedf0adcfa
commit
1bb08f72e6
11 changed files with 224 additions and 101 deletions
|
@ -16,7 +16,8 @@ import { showErrorToast } from "~/utils/errors/showToast";
|
|||
import styles from "./styles.module.scss";
|
||||
|
||||
interface NoteCreationFormProps {
|
||||
onSubmit: (text: string, callback: (note: Note) => void) => void;
|
||||
text?: string;
|
||||
onSubmit: (text: string, callback: () => void) => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
|
@ -27,15 +28,16 @@ const validationSchema = object({
|
|||
type Values = Asserts<typeof validationSchema>;
|
||||
|
||||
const NoteCreationForm: FC<NoteCreationFormProps> = ({
|
||||
text = "",
|
||||
onSubmit,
|
||||
onCancel,
|
||||
}) => {
|
||||
const placeholder = useRandomPhrase("SIMPLE");
|
||||
|
||||
const submit = useCallback<FormikConfig<Values>["onSubmit"]>(
|
||||
async ({ text }, { resetForm, setSubmitting, setErrors }) => {
|
||||
async (values, { resetForm, setSubmitting, setErrors }) => {
|
||||
try {
|
||||
await onSubmit(text, () => resetForm());
|
||||
await onSubmit(values.text, () => resetForm());
|
||||
} catch (error) {
|
||||
const message = getErrorMessage(error);
|
||||
if (message) {
|
||||
|
@ -58,8 +60,9 @@ const NoteCreationForm: FC<NoteCreationFormProps> = ({
|
|||
handleSubmit,
|
||||
touched,
|
||||
handleBlur,
|
||||
isSubmitting,
|
||||
} = useFormik<Values>({
|
||||
initialValues: { text: "" },
|
||||
initialValues: { text },
|
||||
validationSchema,
|
||||
onSubmit: submit,
|
||||
});
|
||||
|
@ -85,7 +88,7 @@ const NoteCreationForm: FC<NoteCreationFormProps> = ({
|
|||
Отмена
|
||||
</Button>
|
||||
|
||||
<Button size="mini" type="submit" color="gray">
|
||||
<Button size="mini" type="submit" color="gray" loading={isSubmitting}>
|
||||
ОК
|
||||
</Button>
|
||||
</Group>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue