divinorg / kit

https://indivorg.github.io/kit
Apache License 2.0
0 stars 0 forks source link

Write a generalised error handling/success notification component using react-hot-toast #27

Open simenandre opened 2 years ago

simenandre commented 2 years ago

Moved here from indivorg/app#457. Originally created by @braaar

Currently, Alert requires a lot of manual implementation.

I think it could be useful to make a component that shows react-hot-toast notifications for common operations.

I think it would be simplest if this component can just take in the data, error and loading objects you get from query and mutation hooks:

const [
    updatePlanMutation,
    {data: updateData, loading: updateLoading, error: updateError},
  ] = useUpdatePlanMutation({
    variables: {
      id: planId, // value for 'id'
      plan: null, // value for 'plan'
      tenantId, // value for 'tenantId'
    },
  });

Not sure how we would want it to behave. Let's discuss!

For mutations (create, update, delete):

For queries:

braaar commented 2 years ago

I have already implemented some functions in app/src/services/toast-helpers.ts to make it easy to show toasts when we perform mutations. I'm not sure how an improved Alert component would look like, but I think there are some improvements that could be made.

What if we make the Skeleton component a part of this? If we get an error the skeletons can become orange or something?