Merge branch 'fix-input-field-error-not-shown' into uncategorised

This commit is contained in:
Abhinav 2023-02-02 13:28:42 +05:30
commit e64f1c9ad7
3 changed files with 37 additions and 22 deletions

View file

@ -15,7 +15,8 @@ export default function EmailShare({ collection }) {
const collectionShare: SingleInputFormProps['callback'] = async ( const collectionShare: SingleInputFormProps['callback'] = async (
email, email,
setFieldError setFieldError,
resetForm
) => { ) => {
try { try {
const user: User = getData(LS_KEYS.USER); const user: User = getData(LS_KEYS.USER);
@ -28,6 +29,7 @@ export default function EmailShare({ collection }) {
} else { } else {
await shareCollection(collection, email); await shareCollection(collection, email);
await galleryContext.syncWithRemote(false, true); await galleryContext.syncWithRemote(false, true);
resetForm();
} }
} catch (e) { } catch (e) {
const errorMessage = handleSharingErrors(e); const errorMessage = handleSharingErrors(e);

View file

@ -400,28 +400,39 @@ function PhotoViewer(props: Iprops) {
}; };
const updateItems = (items = []) => { const updateItems = (items = []) => {
if (photoSwipe) { try {
if (items.length === 0) { if (photoSwipe) {
photoSwipe.close(); if (items.length === 0) {
} photoSwipe.close();
photoSwipe.items.length = 0; }
items.forEach((item) => { photoSwipe.items.length = 0;
photoSwipe.items.push(item); items.forEach((item) => {
}); photoSwipe.items.push(item);
photoSwipe.invalidateCurrItems(); });
if (isOpen) {
photoSwipe.updateSize(true); photoSwipe.invalidateCurrItems();
if (photoSwipe.getCurrentIndex() >= photoSwipe.items.length) { if (isOpen) {
photoSwipe.goTo(0); photoSwipe.updateSize(true);
if (
photoSwipe.getCurrentIndex() >= photoSwipe.items.length
) {
photoSwipe.goTo(0);
}
} }
} }
} catch (e) {
logError(e, 'updateItems failed');
} }
}; };
const refreshPhotoswipe = () => { const refreshPhotoswipe = () => {
photoSwipe.invalidateCurrItems(); try {
if (isOpen) { photoSwipe.invalidateCurrItems();
photoSwipe.updateSize(true); if (isOpen) {
photoSwipe.updateSize(true);
}
} catch (e) {
logError(e, 'refreshPhotoswipe failed');
} }
}; };

View file

@ -1,6 +1,6 @@
import React, { useMemo, useState } from 'react'; import React, { useMemo, useState } from 'react';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { Formik, FormikHelpers } from 'formik'; import { Formik, FormikHelpers, FormikState } from 'formik';
import * as Yup from 'yup'; import * as Yup from 'yup';
import SubmitButton from './SubmitButton'; import SubmitButton from './SubmitButton';
import TextField from '@mui/material/TextField'; import TextField from '@mui/material/TextField';
@ -14,7 +14,8 @@ interface formValues {
export interface SingleInputFormProps { export interface SingleInputFormProps {
callback: ( callback: (
inputValue: string, inputValue: string,
setFieldError: (errorMessage: string) => void setFieldError: (errorMessage: string) => void,
resetForm: (nextState?: Partial<FormikState<formValues>>) => void
) => Promise<void>; ) => Promise<void>;
fieldType: 'text' | 'email' | 'password'; fieldType: 'text' | 'email' | 'password';
placeholder: string; placeholder: string;
@ -43,10 +44,11 @@ export default function SingleInputForm(props: SingleInputFormProps) {
{ setFieldError, resetForm }: FormikHelpers<formValues> { setFieldError, resetForm }: FormikHelpers<formValues>
) => { ) => {
SetLoading(true); SetLoading(true);
await props.callback(values.inputValue, (message) => await props.callback(
setFieldError('inputValue', message) values.inputValue,
(message) => setFieldError('inputValue', message),
resetForm
); );
resetForm();
SetLoading(false); SetLoading(false);
}; };