Skip to content

Instantly share code, notes, and snippets.

@SangeetAgarwal
Last active September 5, 2020 18:16
Show Gist options
  • Save SangeetAgarwal/0c6152c1da1a5917020e32a6a29de6ef to your computer and use it in GitHub Desktop.
Save SangeetAgarwal/0c6152c1da1a5917020e32a6a29de6ef to your computer and use it in GitHub Desktop.
Skeletal of the presentation component that receives data as props
const ResourceEdit = ({
resource,
mappedCategories,
mappedCategoryContentAreas,
mappedTopics,
}: {
resource: DataAccess.ResourceApiModel;
mappedCategories: { [key: string]: string };
mappedCategoryContentAreas: { [key: string]: string };
mappedTopics: { [key: string]: string };
}) => {
React.useEffect(() => {
setSafeCategoryContentAreas(mappedCategoryContentAreas);
setSafeCategories(mappedCategories);
setSafeTopics(mappedTopics);
return function cleanup() {
};
}, [resource, mappedTopics, mappedCategories, mappedCategoryContentAreas]);
const validate = (values: IFormFields) => {
};
const onSubmit = async (
values: IFormFields,
actions: FormikHelpers<IFormFields>
) => {
await retry(
async (bail) => {
try {
await axios(config);
} catch (e) {
const error = e as AxiosError;
if (
error.response &&
(error.response.status === 400 ||
error.response.status === 401 ||
error.response.status === 403)
) {
bail(e);
} else {
throw e;
}
},
{ retries: 3 }
);
// then, mutate to refresh cached resource
mutate(["/api/resource", values.id as string]);
}; // OnSubmit Ends
const onReset = (values: IFormFields) => {
// These are outside the purview of formik so need to manage these manually
};
// Formik hook
const formikBag = useFormik({
initialValues,
validate,
onSubmit,
onReset,
enableReinitialize: true,
});
return (
<>
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment