Skip to content

Commit

Permalink
Merge pull request #1818 from ResearchHub/remove-authorship
Browse files Browse the repository at this point in the history
Remove authorship in paper claim process
  • Loading branch information
yattias authored Aug 22, 2024
2 parents 6e56988 + e04be39 commit 46bf0e3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 91 deletions.
36 changes: 10 additions & 26 deletions components/Author/Profile/AuthorPublications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { css, StyleSheet } from "aphrodite";
import { useEffect, useState } from "react";
import {
UnifiedCard,
getDocumentCard,
} from "~/components/UnifiedDocFeed/utils/getDocumentCard";
import AddPublicationsModal from "~/components/Publication/AddPublicationsModal";
import { ROUTES as WS_ROUTES } from "~/config/ws";
import { useSelector, connect, useDispatch } from "react-redux";
import Button from "~/components/Form/Button";
import { ID, parseUser } from "~/config/types/root_types";
import { ID, parseAuthorProfile, parseUser } from "~/config/types/root_types";
import { RootState } from "~/redux";
import { filterNull, isEmpty } from "~/config/utils/nullchecks";
import UnifiedDocFeedCardPlaceholder from "~/components/UnifiedDocFeed/UnifiedDocFeedCardPlaceholder";
Expand All @@ -31,13 +30,6 @@ import {
getFEUnifiedDocType,
} from "~/config/utils/getUnifiedDocType";
import FeedCard from "../Tabs/FeedCard";
import {
Authorship,
parseAuthorship,
parseGenericDocument,
parsePaper,
} from "~/components/Document/lib/types";
import MoreHoriz from "@mui/icons-material/MoreHoriz";
import ClaimRewardsModal from "~/components/ResearchCoin/ClaimRewardsModal";
import ClaimRewardsButton from "~/components/shared/ClaimRewardsButton";
import { getRewardsEligibilityInfo } from "~/components/ResearchCoin/lib/rewardsUtil";
Expand All @@ -49,8 +41,6 @@ import { MessageActions } from "~/redux/message";
import { useAlert } from "react-alert";
import { Tooltip } from "@mui/material";
import VerifyIdentityModal from "~/components/Verification/VerifyIdentityModal";
import { faLongArrowDown } from "@fortawesome/pro-regular-svg-icons";
import { ClipLoader } from "react-spinners";
import LoadMore from "~/components/shared/LoadMore";
import SearchEmpty from "~/components/Search/SearchEmpty";
import { breakpoints } from "~/config/themes/screen";
Expand Down Expand Up @@ -78,20 +68,17 @@ const AuthorPublications = ({
isOpen: boolean;
paperId: string | null;
paperTitle: string;
authorship: Authorship | null;
}>({
isOpen: false,
paperId: null,
paperTitle: "",
authorship: null,
});

const resetRewardsModalState = () => {
setRewardsModalState({
isOpen: false,
paperId: null,
paperTitle: "",
authorship: null,
});
};

Expand All @@ -104,6 +91,8 @@ const AuthorPublications = ({
setFullAuthorProfile,
setIsLoadingPublications,
isLoadingPublications,
summaryStats,
setSummaryStats,
} = authorProfileContext();

useEffect(() => {
Expand Down Expand Up @@ -175,7 +164,6 @@ const AuthorPublications = ({
paperId={rewardsModalState.paperId}
isOpen={rewardsModalState.isOpen}
paperTitle={rewardsModalState.paperTitle}
authorship={rewardsModalState.authorship}
closeModal={() => resetRewardsModalState()}
/>

Expand Down Expand Up @@ -304,18 +292,20 @@ const AuthorPublications = ({
: docTypeLabel === "discussion"
? "post"
: docTypeLabel;


const targetDoc = !RESEARCHHUB_POST_DOCUMENT_TYPES.includes(
formattedDocType
)
? uniDoc.documents
: uniDoc.documents[0];
const docID = targetDoc.id;

const authorships: Authorship[] =
targetDoc.authorships.map(parseAuthorship);

const authors = targetDoc.authors.map(parseAuthorProfile);

const rewardEligibilityInfo = getRewardsEligibilityInfo({
authorships,
authors,
fullAuthorProfile,
targetDoc,
isOpenAccess: targetDoc.is_open_access,
Expand Down Expand Up @@ -354,10 +344,9 @@ const AuthorPublications = ({
...publicationsResponse,
};

fullAuthorProfile.summaryStats.worksCount =
fullAuthorProfile.summaryStats.worksCount - 1;
setFullAuthorProfile({ ...fullAuthorProfile });
summaryStats.worksCount = summaryStats.worksCount - 1
setPublicationsResponse(updatedResponse);
setSummaryStats({ ...summaryStats });
})
.catch(() => {
dispatch(
Expand Down Expand Up @@ -388,11 +377,6 @@ const AuthorPublications = ({
setRewardsModalState({
paperId: targetDoc.id,
paperTitle: targetDoc.title,
authorship:
authorships.find(
(authorship) =>
authorship.authorId === fullAuthorProfile.id
) || null,
isOpen: true,
});
}}
Expand Down
47 changes: 13 additions & 34 deletions components/Author/Tabs/FeedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { PaperActions } from "~/redux/paper";
import {
AuthorProfile,
RhDocumentType,
UnifiedDocument,
} from "~/config/types/root_types";
import { useState, useEffect, SyntheticEvent } from "react";
import colors, {
Expand All @@ -41,10 +40,8 @@ import ContentBadge from "~/components/ContentBadge";
import { useRouter } from "next/router";
import Link from "next/link";
import {
Authorship,
Paper,
Post,
parseAuthorship,
parsePaper,
parsePost,
} from "~/components/Document/lib/types";
Expand Down Expand Up @@ -305,26 +302,6 @@ function FeedCard({
numOfVisibleHubs--;
}

// We want to shim all authors into the authorship format so it renders properly.
// To properly address, we will need to refactor this component.
let authorships: Authorship[] = [];
if (document?.authorships?.length > 0) {
authorships = document.authorships.map(a => parseAuthorship(a));
}
else if (authors && authors.length > 0) {
authorships = authors.map(a => {
const rawAuthorship = {
raw_author_name: a.firstName + " " + a.lastName,
id: a.id,
author: {
profile_image: a.profileImage,
id: a.id,
}
}
return parseAuthorship(rawAuthorship);
});
}

return (
<div
className={css(
Expand Down Expand Up @@ -376,12 +353,12 @@ function FeedCard({

<div style={{ display: "flex" }}>
<div style={{ display: "flex", gap: 5, alignItems: "center", width: "100%", }}>
{Boolean(authorships[0]) && (
{Boolean(authors[0]) && (
<span className={css(styles.authors)}>
{authorships[0].rawAuthorName}
{authors[0].firstName + " " + authors[0].lastName}
</span>
)}
{authorships?.length > 1 && <span>{` et al.`}</span>}
{authors?.length > 1 && <span>{` et al.`}</span>}

{parsedDoc?.createdDate && (
<>
Expand All @@ -394,7 +371,7 @@ function FeedCard({

<div style={{ alignSelf: "flex-end", marginLeft: "auto", }}>
<AvatarGroup
total={authorships.length}
total={authors.length}
max={4}
spacing={6}
componentsProps={{
Expand All @@ -407,13 +384,15 @@ function FeedCard({
}
}}
>
{authorships.map((authorship) => (
<Tooltip title={authorship.rawAuthorName}>
<Avatar src={authorship.author.profileImage} sx={{ width: 22, height: 22, fontSize: 13, }}>
{isEmpty(authorship.author.profileImage) && authorship.rawAuthorName[0]}
</Avatar>
</Tooltip>
))}
{authors.map((author) => {
return (
<Tooltip title={author.firstName + " " + author.lastName}>
<Avatar src={author.profileImage} sx={{ width: 22, height: 22, fontSize: 13, }}>
{isEmpty(author.profileImage) && (author.firstName || "")[0]}
</Avatar>
</Tooltip>
)
})}
</AvatarGroup>
</div>

Expand Down
17 changes: 0 additions & 17 deletions components/Document/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,8 @@ export type ReviewSummary = {
};

export type Authorship = {
id: ID;
authorId: ID;
authorPosition: "first" | "last" | "middle";
isCorresponding: boolean;
rawAuthorName: string;
author: AuthorProfile;
};

export interface GenericDocument {
Expand Down Expand Up @@ -133,7 +129,6 @@ export type Paper = GenericDocument & {
pdfUrl?: string;
proxyPdfUrl?: string;
pdfCopyrightAllowsDisplay?: boolean;
authorships: Authorship[];
};

export type Post = GenericDocument & {
Expand Down Expand Up @@ -165,17 +160,6 @@ export const parseNote = (raw: any): Note => {
};
};

export const parseAuthorship = (raw: any): Authorship => {
return {
id: raw.id,
authorId: raw.author_id,
authorPosition: raw.author_position,
isCorresponding: raw.is_corresponding,
rawAuthorName: raw.raw_author_name,
author: parseAuthorProfile(raw.author),
};
};

export const parseReviewSummary = (raw: any): ReviewSummary => {
return {
count: raw?.count || 0,
Expand Down Expand Up @@ -231,7 +215,6 @@ export const parsePaper = (raw: any, shouldStripHTML = true): Paper => {
pdfUrl: raw.pdf_url,
proxyPdfUrl: raw.pdf_url ? proxyApi.generateProxyUrl(raw.pdf_url) : null,
pdfCopyrightAllowsDisplay: Boolean(raw.pdf_copyright_allows_display),
authorships: (raw.authorships || []).map((a: any) => parseAuthorship(a)),
...(raw.pdf_license && { license: raw.pdf_license }),
};

Expand Down
2 changes: 1 addition & 1 deletion components/Notifications/NotificationEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const NotificationEntry = (props) => {
if (notification_type === "IDENTITY_VERIFICATION_UPDATED") {
return "Congratulations! Your account has been verified by the ResearchHub team. ";
} else if (notification_type === "PAPER_CLAIM_PAYOUT") {
return "Congratulations! You claim has been approved and RSC has been awarded to your account.";
return "Congratulations! Your claim has been approved and RSC has been awarded to your account.";
} else if (notification_type === "PUBLICATIONS_ADDED") {
return (
<div style={{ display: "flex", flexDirection: "column" }}>
Expand Down
4 changes: 0 additions & 4 deletions components/ResearchCoin/ClaimRewardsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { submitRewardsClaim, fetchEligiblePaperRewards } from "./lib/api";
import useCurrentUser from "~/config/hooks/useCurrentUser";
import { ID } from "~/config/types/root_types";
import { Authorship } from "../Document/lib/types";
import { RewardSummary, parseRewardSummary } from "./lib/types";
import ClaimRewardSummary from "./lib/ClaimRewardSummary";
import FormInput from "../Form/FormInput";
Expand All @@ -29,7 +28,6 @@ interface Props {
isOpen: boolean;
paperId: ID;
paperTitle: string;
authorship: Authorship | null;
closeModal: () => void;
}

Expand Down Expand Up @@ -128,7 +126,6 @@ const blockStyles = StyleSheet.create({
const ClaimRewardsModal = ({
paperId,
paperTitle,
authorship,
isOpen,
closeModal,
}: Props) => {
Expand Down Expand Up @@ -167,7 +164,6 @@ const ClaimRewardsModal = ({
try {
const response = await submitRewardsClaim({
paperId,
authorshipId: authorship!.id,
userId: currentUser.id,
preregistrationUrl,
openDataUrl,
Expand Down
3 changes: 0 additions & 3 deletions components/ResearchCoin/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import { Helpers } from "@quantfive/js-web-config";

interface Props {
paperId: ID;
authorshipId: ID;
userId: ID;
preregistrationUrl?: string | null;
openDataUrl?: string | null;
}

export const submitRewardsClaim = ({
paperId,
authorshipId,
userId,
preregistrationUrl,
openDataUrl,
Expand All @@ -22,7 +20,6 @@ export const submitRewardsClaim = ({
url,
API.POST_CONFIG({
target_paper_id: paperId,
authorship_id: authorshipId,
requestor: userId,
creator: userId,
...(openDataUrl ? {open_data_url: openDataUrl} : {}),
Expand Down
20 changes: 14 additions & 6 deletions components/ResearchCoin/lib/rewardsUtil.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { FullAuthorProfile } from "~/components/Author/lib/types";
import { AuthorProfile } from "~/config/types/root_types";

export type ineligibleReason =
| "NOT_OPEN_ACCESS"
| "NOT_SUPPORTED_TYPE"
Expand All @@ -10,15 +13,20 @@ export type RewardsEligibilityInfo = {
};

export const getRewardsEligibilityInfo = ({
authorships,
authors,
fullAuthorProfile,
targetDoc,
isOpenAccess,
}: {
authors: AuthorProfile[];
fullAuthorProfile: FullAuthorProfile;
targetDoc: any;
isOpenAccess: boolean;
}): RewardsEligibilityInfo => {
const isFirstAuthor = authorships.find(
(authorship) =>
authorship.authorPosition === "first" &&
authorship.authorId === fullAuthorProfile.id
const isFirstAuthor = authors.find(
(author) =>
author?.authorship?.authorPosition === "first" &&
author.id === fullAuthorProfile.id
);
const isSupportedType = ["article", "preprint"].includes(
targetDoc?.work_type
Expand All @@ -34,7 +42,7 @@ export const getRewardsEligibilityInfo = ({
}

return {
isEligibleForRewards: isFirstAuthor && isSupportedType,
isEligibleForRewards: Boolean(isFirstAuthor && isSupportedType),
reason: ineligibleReason,
};
};
Loading

0 comments on commit 46bf0e3

Please sign in to comment.