Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(message response): convert to functional component #1541

Merged
merged 2 commits into from
Mar 14, 2023

Conversation

ajohn25
Copy link
Contributor

@ajohn25 ajohn25 commented Dec 4, 2022

Description

This converts the message response component in message review to a functional component

Motivation and Context

Best practices, better support for codegen in this component for #1526

How Has This Been Tested?

This has been tested locally

Screenshots (if appropriate):

Documentation Changes

Checklist:

  • My change requires a change to the documentation.
  • I have included updates for the documentation accordingly.

@ajohn25 ajohn25 requested review from hiemanshu and bchrobot December 4, 2022 01:16
@ajohn25 ajohn25 force-pushed the refactor-message-response branch from c961e6e to 0eb79ea Compare December 4, 2022 01:30
@ajohn25 ajohn25 force-pushed the refactor-message-response branch from 0eb79ea to e4ad01e Compare December 4, 2022 01:53
libs/spoke-codegen/src/graphql/message-sending.graphql Outdated Show resolved Hide resolved
Comment on lines 56 to 66
const { data } = await sendMessage({
variables: { message, campaignContactId: contact.id as string }
});
const messages = data?.sendMessage?.messages;

if (messages) {
props.messagesChanged(messages);
props.onChange?.("");
}
} catch (e: any) {
setSendError(e.message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required: take this opportunity to handle errors property in GraphQL response (these errors will not be thrown)

Suggested change
const { data } = await sendMessage({
variables: { message, campaignContactId: contact.id as string }
});
const messages = data?.sendMessage?.messages;
if (messages) {
props.messagesChanged(messages);
props.onChange?.("");
}
} catch (e: any) {
setSendError(e.message);
const { data, errors } = await sendMessage({
variables: { message, campaignContactId: contact.id as string }
});
const messages = data?.sendMessage?.messages;
if (errors) ...
if (messages) {
props.messagesChanged(messages);
props.onChange?.("");
}
} catch (e: any) {
setSendError(e.message);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say more about the errors that won't get thrown/caught here? This GraphQL error for example does get caught successfully currently
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a server-side log, correct?

The client-side call to await sendMessage() won't throw. While the error is logged server-side, client-side the operation returns with both data and errors properties and leaves it up to the user to decide how they want to handle the error condition(s).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed myself up between versions of code 🤦🏾‍♂️ fix is in!

Copy link
Member

@bchrobot bchrobot Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good!

As an aside (definitely beyond scope of this PR), I added another to-do on the conventions task for standardizing how we display GraphQL errors. cc @hiemanshu

};

export default loadData({ mutations })(MessageResponse);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Contributor

@hiemanshu hiemanshu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! A small suggestion is all.

isSending: false,
sendError: ""
};
const MessageResponse: React.FC<MessageResponseProps> = (props) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: expand props to { conversation, value, onChange, messagedChanged } easier to access without props.<something>

@ajohn25 ajohn25 requested a review from bchrobot December 6, 2022 23:52
@hiemanshu hiemanshu added this to the 6.2.0 milestone Dec 7, 2022
@hiemanshu hiemanshu merged commit b8b68dd into main Mar 14, 2023
@hiemanshu hiemanshu deleted the refactor-message-response branch March 14, 2023 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants