import React, { useCallback } from 'react' import { Container } from '@toptal/picasso' import { SPACING_4 } from '@toptal/picasso-utils' import { FormNonCompound, Input, SubmitButton } from '@toptal/picasso-forms' const BackendCommunicationExample = () => { const handleSuccessSubmit = useCallback( (values: any) => api.successSubmit(values), [] ) const handleSubmitWithInlineError = useCallback( (values: any) => api.submitWithInlineError(values), [] ) const handleSubmitWithCustomNotificationError = useCallback( (values: any) => api.submitWithCustomNotificationError(values), [] ) return ( Login Success Login with Inline Error Login with Custom Notification Error ) } // the emulation of the api call const responseWithDelay = async (response: any) => new Promise(resolve => setTimeout(() => resolve(response), 2000)) const api = { successSubmit: (values: any) => { // do something with received values console.log('Success submit. Form values:', values) return responseWithDelay(undefined) }, submitWithInlineError: (values: any) => { console.log('Submit with Inline Errors. Form values:', values) return responseWithDelay({ 'backendCommunication-inlineErrorName': 'Unknown first name', }) }, submitWithCustomNotificationError: (values: any) => { console.log('Submit with Custom Notification Errors. Form values:', values) return responseWithDelay('Custom Notification Message!') }, } export default BackendCommunicationExample