Skip to content

Commit

Permalink
fix(openalex): Reset corrections after feedback submission
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 21, 2024
1 parent 2ac7342 commit b7742e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import useToast from '../../../hooks/useToast';

const { VITE_WS_HOST } = import.meta.env;

export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) {
export default function SendFeedbackButton({ allOpenalexCorrections, setAllOpenalexCorrections }) {
const [isModalOpen, setIsModalOpen] = useState(false);
const [userEmail, setUserEmail] = useState(null);
const [validEmail, setValidEmail] = useState(null);
Expand All @@ -39,7 +39,7 @@ export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) {
shouldReconnect: () => true,
});

const feedback = async () => {
const sendFeedback = async () => {
try {
sendJsonMessage({ data: allOpenalexCorrections, email: userEmail, type: 'openalex-affiliations' });
toast({
Expand All @@ -48,6 +48,7 @@ export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) {
id: 'initOpenAlex',
title: 'OpenAlex corrections submitted',
});
setAllOpenalexCorrections([]);
} catch (error) {
toast({
description: error.message,
Expand All @@ -70,11 +71,13 @@ export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) {
return (
<>
<Button
aria-label="Send feedback to OpenAlex"
color="blue-ecume"
disabled={!allOpenalexCorrections.length > 0}
icon="send-plane-fill"
onClick={switchModal}
size="sm"
title="Send feedback to OpenAlex"
>
Send feedback to OpenAlex
</Button>
Expand All @@ -91,8 +94,9 @@ export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) {
</ModalContent>
<ModalFooter>
<Button
aria-label="Send feedback to OpenAlex"
disabled={!allOpenalexCorrections.length > 0 || !validEmail}
onClick={feedback}
onClick={sendFeedback}
title="Send feedback to OpenAlex"
>
Send feedback to OpenAlex
Expand All @@ -103,7 +107,7 @@ export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) {
);
}

ActionsOpenalexFeedback.propTypes = {
SendFeedbackButton.propTypes = {
allOpenalexCorrections: PropTypes.arrayOf(
PropTypes.shape({
rawAffiliationString: PropTypes.string.isRequired,
Expand All @@ -113,4 +117,5 @@ ActionsOpenalexFeedback.propTypes = {
worksOpenAlex: PropTypes.arrayOf(PropTypes.string).isRequired,
}),
).isRequired,
setAllOpenalexCorrections: PropTypes.func.isRequired,
};
1 change: 1 addition & 0 deletions client/src/pages/openalex-ror/results/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ export default function Affiliations() {
/>
<SendFeedbackButton
allOpenalexCorrections={allOpenalexCorrections}
setAllOpenalexCorrections={setAllOpenalexCorrections}
/>
</div>
</div>
Expand Down

0 comments on commit b7742e9

Please sign in to comment.