Skip to content

Commit

Permalink
retweet contribution page, submit, congrats screen, retweet api call
Browse files Browse the repository at this point in the history
  • Loading branch information
AntGe committed Oct 29, 2024
1 parent ddc2c73 commit 2d3a22b
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 73 deletions.
222 changes: 219 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/components/OAuth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const useOAuthSocials = () => {
}, []);

const getAuthX = useCallback(async (onSuccess, onFailure) => {
localStorage.removeItem("OAUTH_RESPONSE");
setAuthenticating(true);
if (popupRef.current && !popupRef.current.closed) {
popupRef.current.close();
Expand All @@ -188,6 +189,8 @@ export const useOAuthSocials = () => {
if (error) {
onFailure(error);
} else {
// eslint-disable-next-line no-debugger
debugger;
xCleanUp(xIntervalRef);
const response = await axios.post(
`${environment.apiUrl}/aut/config/oauth2AccessTokenX`,
Expand All @@ -196,6 +199,7 @@ export const useOAuthSocials = () => {
callbackUrl
}
);

setAuthenticating(false);
clearInterval(intervalRef.current);
popupRef.current.close();
Expand All @@ -204,6 +208,8 @@ export const useOAuthSocials = () => {
}
}
} catch (genericError) {
// eslint-disable-next-line no-debugger
debugger;
onFailure(genericError);
console.error(genericError);
}
Expand Down Expand Up @@ -240,6 +246,9 @@ export const useOAuthSocials = () => {
callbackUrl
}
);

// eslint-disable-next-line no-debugger
debugger;
setAuthenticating(false);
popupRef.current.close();
onSuccess(response.data);
Expand Down
29 changes: 16 additions & 13 deletions src/pages/AutID/AutHub/AutHubContributionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,22 @@ export const AutHubTasksTable = ({ header }) => {
take: 1000
}
});
useEffect(() => {
if (!contributions.length) {
const updatedContributions = data?.map((item) => ({
...item,
contributionType: "open",
status: TaskStatus.Created,
id: generateRandomId()
}));
dispatch(
updateContributionState({ contributions: updatedContributions })
);
}
}, [data]);
useEffect(() => {
if (!contributions.length) {
const updatedContributions = data?.map((item) => ({
...item,
contributionType: (item.properties as any)
.tweetUrl
? "retweet"
: "open",
status: TaskStatus.Created,
id: generateRandomId()
}));
dispatch(
updateContributionState({ contributions: updatedContributions })
);
}
}, [data]);

const theme = useTheme();
return (
Expand Down
1 change: 1 addition & 0 deletions src/pages/Oauth2/Callback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Callback = () => {
});
} else {
console.log("POST MESSAGE");
// localStorage.setItem("OAUTH_RESPONSE", JSON.stringify({ payload }));
window.opener.postMessage({
type: "OAUTH_RESPONSE",
payload
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Tasks/Contributions/Contributions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Contributions = () => {
{contribution?.contributionType === "quiz" && (
<QuizTask contribution={contribution} />
)}
{contribution?.contributionType === "twitter" && (
{contribution?.contributionType === "retweet" && (
<TwitterTask contribution={contribution} />
)}
</>
Expand Down
93 changes: 67 additions & 26 deletions src/pages/Tasks/TwitterTask/TwitterTask.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { memo, useState } from 'react';
import { memo, useState } from "react";
import {
Box,
Card,
CardContent,
Container,
Link,
Stack,
Typography
} from "@mui/material";
Expand All @@ -15,8 +16,11 @@ import { AutOsButton } from "@components/AutButton";
import TaskDetails from "../Shared/TaskDetails";
import SubmitDialog from "@components/Dialog/SubmitDialog";
import AutLoading from "@components/AutLoading";
import { useOAuthSocials } from '@components/OAuth';
import { useAccount } from 'wagmi';
import { useOAuthSocials } from "@components/OAuth";
import { useAccount } from "wagmi";
import { useMutation } from "@tanstack/react-query";
import axios from "axios";
import { environment } from "@api/environment";

const TwitterSubmitContent = ({ contribution, userAddress }) => {
const [loading, setLoading] = useState(false);
Expand All @@ -27,37 +31,58 @@ const TwitterSubmitContent = ({ contribution, userAddress }) => {
const { autAddress, hubAddress } = useParams();
const { getAuthX } = useOAuthSocials();

const { mutateAsync: verifyTetweetTask } = useMutation<any, void, any>({
mutationFn: (verifyRetweetRequest) => {
return axios
.post(
`${environment.apiUrl}/task/twitter/retweet`,
verifyRetweetRequest
)
.then((res) => res.data);
}
});

const handleSubmit = async () => {
await getAuthX(
async (data) => {
const { access_token } = data;
setLoading(true);

try {
// Here you would typically make your API call to verify the twitter action
await new Promise((resolve) => setTimeout(resolve, 3000)); // Simulating API call

dispatch(
updateContributionById({
id: contribution?.id,
data: {
...contribution,
status: TaskStatus.Submitted,
submission: {
properties: {
twitterToken: access_token
}
}
await verifyTetweetTask(
{
accessToken: access_token,
contributionId: contribution?.id,
tweetUrl: contribution.properties?.tweetUrl
},
{
onSuccess: (response) => {
dispatch(
updateContributionById({
id: contribution?.id,
data: {
...contribution,
status: TaskStatus.Submitted,
submission: {
properties: {
twitterToken: access_token
}
}
}
})
);

setOpenSubmitSuccess(true);
setLoading(false);
},
onError: (res) => {
console.error("Failed to submit contribution:", res);
}
})
}
);

setLoading(false);
setOpenSubmitSuccess(true);
} catch (error) {
setLoading(false);
// Handle error case
console.error('Failed to submit contribution:', error);
console.error("Failed to submit contribution:", error);
}
},
() => {
Expand Down Expand Up @@ -132,7 +157,23 @@ const TwitterSubmitContent = ({ contribution, userAddress }) => {
>
{contribution?.description}
</Typography>


<Link
href={contribution.properties?.tweetUrl}
target="_blank"
color="primary"
underline="none"
>
<Typography
color="primary"
variant="body2"
textAlign="center"
marginBottom="16px"
>
{contribution.properties?.tweetUrl}
</Typography>
</Link>

<Typography
color="white"
variant="body2"
Expand All @@ -152,7 +193,7 @@ const TwitterSubmitContent = ({ contribution, userAddress }) => {
}}
>
<Typography fontWeight="bold" fontSize="16px" lineHeight="26px">
Verify with Twitter
Claim
</Typography>
</AutOsButton>
</CardContent>
Expand Down Expand Up @@ -223,4 +264,4 @@ const TwitterTask = ({ contribution }) => {
);
};

export default memo(TwitterTask);
export default memo(TwitterTask);
58 changes: 31 additions & 27 deletions src/utils/format-contribution-type.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
export const formatContributionType = (type: string) => {
switch (type) {
case "discord":
return "Discord";
case "open":
return "Open Task";
case "quiz":
return "Quiz";
case "github":
return "GitHub";
default:
return type;
}
};
switch (type) {
case "discord":
return "Discord";
case "open":
return "Open Task";
case "quiz":
return "Quiz";
case "github":
return "GitHub";
case "retweet":
return "Retweet";
default:
return type;
}
};

export const getContributionTypeSubtitle = (type: string) => {
switch (type) {
case "discord":
return "Join Discord Task";
case "open":
return "Open Task";
case "quiz":
return "Quiz Task";
case "github":
return "GitHub Task";
default:
return type;
}
};
export const getContributionTypeSubtitle = (type: string) => {
switch (type) {
case "discord":
return "Join Discord Task";
case "open":
return "Open Task";
case "quiz":
return "Quiz Task";
case "github":
return "GitHub Task";
case "retweet":
return "Retweet Task";
default:
return type;
}
};
3 changes: 0 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4601,9 +4601,6 @@ fs-extra@^8.1.0:
fs.realpath@^1.0.0:
version "1.0.0"

fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3:
version "2.3.3"

fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3:
version "2.3.3"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
Expand Down

0 comments on commit 2d3a22b

Please sign in to comment.