hiyaryan / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling distorted thinking and finding alternative modes of thought (i.e. reframing) while cognitive distortions are occurring. The CDJ does that work for you. -- The CDJ is in beta testing!!
https://thecdj.app
3 stars 0 forks source link

Handle errors and server messages. #26

Closed hiyaryan closed 9 months ago

hiyaryan commented 9 months ago

Initial commits adds connect-flash middleware to express app. Creates new FlashMessage and FlashMessages components to handle flash messages on the react app. Adds flash messages to new entry creation (as proof of concept) and directly in the Entry component. This should be extracted to a higher component level (possibly up to the App component level using context since the entire app will use it).

hiyaryan commented 9 months ago

This PR adds flash messages wherever POST, PUT, DELETE, and entries/account GET requests are made. It does this using flash messages. Flash messsages are displayed on the frontend using new utility components, FlashMessages, and FlashMessage, where FlashMessages contains shared state over a set of FlashMessage components. Each FlashMessage` is displayed for a certain amount of time depending on its severity type giving the user presumed ample time to respond to it. See table below.

Flash messages have been attached to most request bodies and input into the bodies of most responses withing reason (this is so the user is not overwhelmed with messages.)

In the process of implementing flash messages, some error handling and messages have been fixed and improved. Some errors not being handled correctly, such as not utilizing the next function and/or ExpressError object, have been fixed, particularly at the top level controllers where errors are thrown to and should be handled accordingly.

With flash messages being implemented, some feature changes were implemented such as not allowing the user the post a chat message if the LLM is not properly configured. Entries can still be posted but the user will be flashed with a message to configure their account.

Small design change unrelated to this PR but too minor for its own PR was fitting the chat messages better on the screen (particularly in mobile view). The messages now take up more space on a single grid row exhibiting a zipper effect and preventing it from being too "skinny" of a column on smaller screens.

FlashMessage Severity Types and Clearing Times severity time (s)
error 25
warning 15
info 20
success 5
hiyaryan commented 9 months ago

Last commit removes alert windows that popped up confirming that forgot password email was sent or password reset successfully used before flash messages were implemented. Additionally, timeouts used for sequencing purposes in Account update and Logout are now properly cleared.