-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
c961e6e
to
0eb79ea
Compare
0eb79ea
to
e4ad01e
Compare
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); |
There was a problem hiding this comment.
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)
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
...rs/AdminIncomingMessageList/components/IncomingMessageList/MessageColumn/MessageResponse.tsx
Outdated
Show resolved
Hide resolved
}; | ||
|
||
export default loadData({ mutations })(MessageResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
There was a problem hiding this 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) => { |
There was a problem hiding this comment.
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>
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: