@@ -24,6 +24,7 @@ import RecordFormStateToggle from '@/components/RecordFormStateToggle';
2424import { GeneralRecordType } from '@/components/types' ;
2525import { cleanPayload , FORM_VARIANT , tuple } from '@/components/util' ;
2626import api from '@/services/api' ;
27+ import { ErrorMessage } from '@/services/errors' ;
2728
2829import CivicEvidenceLink from './CivicEvidenceLink' ;
2930import ReviewDialog from './ReviewDialog' ;
@@ -33,7 +34,6 @@ const FIELD_EXCLUSIONS = ['groupRestrictions'];
3334interface StatementFormProps {
3435 /** the title for this form */
3536 title : string ;
36- onError ?: ( arg : { error : { name ?: string ; message ?: string } ; content : unknown } ) => void ;
3737 onSubmit ?: ( record ?: GeneralRecordType ) => void ;
3838 onToggleState ?: ( newState : FORM_VARIANT | 'graph' ) => void ;
3939 /** values of individual properties of passed class model */
@@ -50,7 +50,6 @@ const StatementForm = ({
5050 title,
5151 onToggleState,
5252 onSubmit,
53- onError,
5453 variant = FORM_VARIANT . VIEW ,
5554} : StatementFormProps ) => {
5655 const params = useParams ( ) ;
@@ -109,6 +108,7 @@ const StatementForm = ({
109108 queryKey : [ `/statements/${ params . rid } ?neighbors=1` ] ,
110109 queryFn : async ( { queryKey : [ route ] } ) => api . get ( route ) ,
111110 enabled : ( isempty ( initialValue ) && Boolean ( params . rid ) ) ,
111+ throwOnError : true ,
112112 } ) ;
113113
114114 const snackbar = useSnackbar ( ) ;
@@ -208,7 +208,7 @@ const StatementForm = ({
208208 return updatedContent ;
209209 } , [ auth ] ) ;
210210
211- const { mutate : addNewAction , isPending : isAdding } = useMutation ( {
211+ const { mutate : addNewAction , isPending : isAdding , error : errorAdding } = useMutation ( {
212212 mutationFn : async ( content : GeneralRecordType ) => {
213213 const payload = cleanPayload ( content ) ;
214214 const { routeName } = schemaDefn . get ( payload ) ;
@@ -218,11 +218,6 @@ const StatementForm = ({
218218 snackbar . enqueueSnackbar ( `Sucessfully created the record ${ result [ '@rid' ] } ` , { variant : 'success' } ) ;
219219 onSubmit ?.( result ) ;
220220 } ,
221- onError : ( err : Error , content ) => {
222- console . error ( err ) ;
223- snackbar . enqueueSnackbar ( `Error (${ err . name } ) in creating the record` , { variant : 'error' } ) ;
224- onError ?.( { error : err , content } ) ;
225- } ,
226221 } ) ;
227222
228223 /**
@@ -242,7 +237,7 @@ const StatementForm = ({
242237 }
243238 } , [ addNewAction , formContent , formErrors , formHasErrors , model . name , setFormIsDirty , snackbar , statementReviewCheck ] ) ;
244239
245- const { mutate : deleteAction , isPending : isDeleting } = useMutation ( {
240+ const { mutate : deleteAction , isPending : isDeleting , error : errorDeleting } = useMutation ( {
246241 mutationFn : async ( content : GeneralRecordType ) => {
247242 const { routeName } = schemaDefn . get ( content ) ;
248243 return api . delete ( `${ routeName } /${ content [ '@rid' ] ! . replace ( / ^ # / , '' ) } ` ) ;
@@ -251,10 +246,6 @@ const StatementForm = ({
251246 snackbar . enqueueSnackbar ( `Sucessfully deleted the record ${ content [ '@rid' ] } ` , { variant : 'success' } ) ;
252247 onSubmit ?.( ) ;
253248 } ,
254- onError : ( err : Error , content ) => {
255- snackbar . enqueueSnackbar ( `Error (${ err . name } ) in deleting the record (${ content [ '@rid' ] } )` , { variant : 'error' } ) ;
256- onError ?.( { error : err , content } ) ;
257- } ,
258249 } ) ;
259250
260251 /**
@@ -265,7 +256,7 @@ const StatementForm = ({
265256 deleteAction ( content ) ;
266257 } , [ deleteAction , formContent , model . name ] ) ;
267258
268- const { mutate : updateAction , isPending : isUpdating } = useMutation ( {
259+ const { mutate : updateAction , isPending : isUpdating , error : errorUpdating } = useMutation ( {
269260 mutationFn : async ( content : GeneralRecordType ) => {
270261 const payload = cleanPayload ( content ) ;
271262 const { routeName } = schemaDefn . get ( payload ) ;
@@ -275,10 +266,6 @@ const StatementForm = ({
275266 snackbar . enqueueSnackbar ( `Sucessfully edited the record ${ result [ '@rid' ] } ` , { variant : 'success' } ) ;
276267 onSubmit ?.( result ) ;
277268 } ,
278- onError : ( err : Error , content ) => {
279- snackbar . enqueueSnackbar ( `Error (${ err . name } ) in editing the record (${ content [ '@rid' ] } )` , { variant : 'error' } ) ;
280- onError ?.( { error : err , content } ) ;
281- } ,
282269 } ) ;
283270
284271 /**
@@ -381,6 +368,9 @@ const StatementForm = ({
381368 modelName = { model . name }
382369 />
383370 </ FormContext . Provider >
371+ < ErrorMessage error = { errorAdding } > An error occurred while creating record.</ ErrorMessage >
372+ < ErrorMessage error = { errorDeleting } > An error occurred while deleting record.</ ErrorMessage >
373+ < ErrorMessage error = { errorUpdating } > An error occurred while updating record.</ ErrorMessage >
384374 < div className = "statement-form__action-buttons" >
385375 { variant === FORM_VARIANT . EDIT && ! formContent . deletedAt
386376 ? (
0 commit comments