From 6747af707198b523c17f01b6cb2b69709003abae Mon Sep 17 00:00:00 2001 From: AntGe Date: Mon, 11 Nov 2024 13:02:04 +0200 Subject: [PATCH 1/4] gh task page, oauth 2 integration, wire endpoints, repos list, org list --- src/api/contribution.model.ts | 33 ++++ .../GithubTasks/CreateGithubCommitTask.tsx | 178 +++++++++++++----- src/pages/TaskManager/index.tsx | 2 +- 3 files changed, 163 insertions(+), 50 deletions(-) diff --git a/src/api/contribution.model.ts b/src/api/contribution.model.ts index db7516b..a9a6d3c 100644 --- a/src/api/contribution.model.ts +++ b/src/api/contribution.model.ts @@ -35,6 +35,39 @@ export class RetweetContribution< ) as T; } } +export class CommitContributionProperties extends TaskContributionProperties { + branch: string; + repository: string; + constructor(data: CommitContributionProperties) { + super(data); + this.branch = data.branch; + this.repository = data.repository; + } +} + +export class CommitContribution< + T = CommitContributionProperties +> extends TaskContributionNFT { + static getContributionNFT( + contribution: CommitContribution + ): BaseNFTModel { + const taskContribution = new CommitContribution(contribution); + return { + name: taskContribution.name, + description: taskContribution.description, + properties: { + branch: taskContribution.properties.branch, + repository: taskContribution.properties.repository + } + } as BaseNFTModel; + } + constructor(data: CommitContribution = {} as CommitContribution) { + super(data); + this.properties = new CommitContributionProperties( + data.properties as CommitContributionProperties + ) as T; + } +} export class OpenTaskContributionProperties extends TaskContributionProperties { attachmentRequired: boolean; diff --git a/src/pages/GithubTasks/CreateGithubCommitTask.tsx b/src/pages/GithubTasks/CreateGithubCommitTask.tsx index 53154b4..f4e723d 100644 --- a/src/pages/GithubTasks/CreateGithubCommitTask.tsx +++ b/src/pages/GithubTasks/CreateGithubCommitTask.tsx @@ -27,6 +27,7 @@ import { useCreateOpenTaskContributionMutation } from "@api/contributions.api"; import { + CommitContribution, DiscordGatheringContribution, OpenTaskContribution } from "@api/contribution.model"; @@ -91,17 +92,16 @@ const AttachmentTypes = [ // } // })); - const CreateGithubCommitTask = () => { const [searchParams] = useSearchParams(); const navigate = useNavigate(); const theme = useTheme(); const hubData = useSelector(HubData); - const autID = useSelector(AutIDData) + const autID = useSelector(AutIDData); - const githubId = useMemo(() => { + const metadata = useMemo(() => { const social = hubData.properties.socials.find((s) => s.type === "github"); - return social.link; + return social.metadata; }, [hubData]); const [loading, setLoading] = useState(false); @@ -113,6 +113,8 @@ const CreateGithubCommitTask = () => { startDate: new Date(), endDate: null, description: "", + repository: "", + branch: "", role: null, duration: null, allCanAttend: false, @@ -122,53 +124,59 @@ const CreateGithubCommitTask = () => { }); const values = watch(); - const { getAuthGithub } = useOAuthSocials(); + // Query to fetch repositories + const { data: reposResponse, isLoading: loadingRepos } = useQuery({ + queryKey: ["repositories", metadata.orgId], + queryFn: async () => { + const response = await axios.post( + "http://localhost:4005/api/task/github/getRepositories", + { + organisationId: metadata.orgId, + organisationName: metadata.orgName + } + ); + return response.data; + }, + enabled: !!metadata.orgId && !!metadata.orgName + }); + // Query to fetch branches when a repository is selected + const { data: branchesResponse, isLoading: loadingBranches } = useQuery({ + queryKey: ["branches", values.repository], + queryFn: async () => { + const response = await axios.post( + "http://localhost:4005/api/task/github/getBranches", + { + repositoryName: values.repository, + organisationName: metadata.orgName + } + ); + return response.data; + }, + enabled: !!values.repository && !!metadata.orgName + }); - const onSubmit = async () => { - // const values = getValues(); - // const contribution = new DiscordGatheringContribution({ - // name: values.title, - // description: values.description, - // image: "", - // properties: { - // taskId: searchParams.get("taskId"), - // role: values.role, - // duration: values.duration, - // startDate: dateToUnix(values.startDate), - // endDate: dateToUnix(values.endDate), - // channelId: values.channelId, - // points: values.weight, - // quantity: 1, - // uri: "" - // } - // }); - // createTask(contribution); + const { getAuthGithub } = useOAuthSocials(); - await getAuthGithub( - async (data) => { - debugger; - const { access_token } = data; - debugger; - setLoading(true); - // const requestModel = { - // discordAccessToken: access_token, - // hubAddress, - // authSig - // }; - // const result = await claimRole(requestModel, { - // onSuccess: (response) => { - // setLoading(false); - // setRoleClaimed(true); - // }, - // onError: (res) => { - // setLoading(false); - // } - // }); - }, - () => { - setLoading(false); + const onSubmit = async (data: any) => { + const values = getValues(); + const joinedHub = autID.joinedHub(hubData.properties.address); + const contribution = new CommitContribution({ + name: values.title, + description: values.description, + image: "", + properties: { + taskId: searchParams.get("taskId"), + role: +joinedHub.role, + startDate: dateToUnix(values.startDate), + endDate: dateToUnix(values.endDate), + points: values.weight, + branch: values.branch, + repository: values.repository, + quantity: values.quantity, + uri: "" } - ); + }); + createTask(contribution); }; // useEffect(() => { @@ -241,7 +249,8 @@ const CreateGithubCommitTask = () => { color="offWhite.main" fontSize="16px" > - Create a task that requires the user to commit to your hub's repository. + Create a task that requires the user to commit to your hub's + repository. { }} /> + {!!reposResponse?.repositories?.length && ( + + + Repository + + ( + + + Select a repository + + {reposResponse?.repositories?.map((repo) => ( + + {repo.name} + + ))} + + )} + /> + + )} + + + + Branch + + ( + + + Select a branch + + {branchesResponse?.branches?.map((branch) => ( + + {branch.name} + + ))} + + )} + /> + { {socials.github ? ( githubTasks.map((taskType, index) => ( - Date: Tue, 12 Nov 2024 18:07:43 +0200 Subject: [PATCH 2/4] added quiz and refactored contributions and some other fixes and iimprovements --- package-lock.json | 29 +- package.json | 6 +- src/App.tsx | 37 +- src/api/aut.api.ts | 13 + .../discord-gathering.model.ts | 2 + .../contribution-types/join-discord.model.ts | 2 + src/api/contribution-types/open-task.model.ts | 2 + .../contribution-types/quiz.model.model.ts | 27 + src/api/contribution-types/retweet.model.ts | 2 + src/api/contribution.model.ts | 5 +- src/api/contributions.api.ts | 114 ++- src/hooks/useQueryContributions.tsx | 3 +- src/index.tsx | 1 + src/pages/AutDashboardMain.tsx | 246 ++--- src/pages/DiscordBot/CreateGathering.tsx | 5 +- .../Plugins/Task/Open/CreateOpenTask.tsx | 10 +- .../Modules/Plugins/Task/Open/OpenTask.tsx | 861 ------------------ .../Plugins/Task/Quiz/CreateQuizTask.tsx | 530 ++++++++++- .../Plugins/Task/Quiz/QuestionsAndAnswers.tsx | 4 +- .../Modules/Plugins/Task/Quiz/QuizTask.tsx | 17 +- .../Modules/Plugins/Task/Quiz/QuizTasks.tsx | 505 ---------- .../Modules/Plugins/Task/Shared/AllTasks.tsx | 146 +-- .../Task/Shared/ContributionsTable.tsx | 12 +- src/pages/Modules/Shared/routes.tsx | 2 +- src/pages/TaskManager/index.tsx | 15 +- src/pages/TwitterTasks/CreateXRetweetTask.tsx | 4 +- src/utils/format-contribution-type.tsx | 29 - 27 files changed, 776 insertions(+), 1853 deletions(-) delete mode 100644 src/pages/Modules/Plugins/Task/Open/OpenTask.tsx delete mode 100644 src/pages/Modules/Plugins/Task/Quiz/QuizTasks.tsx delete mode 100644 src/utils/format-contribution-type.tsx diff --git a/package-lock.json b/package-lock.json index a420349..cc6a23d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,9 +10,9 @@ "dependencies": { "@apollo/client": "^3.9.1", "@aut-labs/abi-types": "^0.0.86-dev", - "@aut-labs/connector": "^0.0.203", - "@aut-labs/d-aut": "^1.0.204-dev", - "@aut-labs/sdk": "^0.0.220-dev", + "@aut-labs/connector": "^0.0.205", + "@aut-labs/d-aut": "^1.0.205-dev", + "@aut-labs/sdk": "^0.0.222-dev", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", "@leenguyen/react-flip-clock-countdown": "^1.4.0", @@ -147,12 +147,14 @@ "node_modules/@aut-labs/abi-types": { "version": "0.0.86-dev", "resolved": "https://registry.npmjs.org/@aut-labs/abi-types/-/abi-types-0.0.86-dev.tgz", - "integrity": "sha512-I9VNsYN8smW516wPQeDWhJaw4OWiIc7WxRBIn2GkqKw4oYKaLbDRzTV2XXVrMlvVCo7V82V51SlV+fC0Hajq/w==" + "integrity": "sha512-I9VNsYN8smW516wPQeDWhJaw4OWiIc7WxRBIn2GkqKw4oYKaLbDRzTV2XXVrMlvVCo7V82V51SlV+fC0Hajq/w==", + "license": "ISC" }, "node_modules/@aut-labs/connector": { - "version": "0.0.203", - "resolved": "https://registry.npmjs.org/@aut-labs/connector/-/connector-0.0.203.tgz", - "integrity": "sha512-bUXlRb1YviVb6jpnTLnZs3HaZhABItep+knkbCsrKAAZcPH0bcsnJsjCfLOH2PsZX+BcTafxUrT2FDmy92aeZw==", + "version": "0.0.205", + "resolved": "https://registry.npmjs.org/@aut-labs/connector/-/connector-0.0.205.tgz", + "integrity": "sha512-TcbRTjHst2mM9SxZRRo0uKoY/dJ5xBuXpeDC8fc9R419nJxLm5cLLAleoNdXMrrSvSHjk7jJ27WEj3VpHGDqmA==", + "license": "MIT", "dependencies": { "@web3auth/base": "^8.0.0", "@web3auth/ethereum-provider": "^8.0.1", @@ -173,14 +175,15 @@ } }, "node_modules/@aut-labs/d-aut": { - "version": "1.0.204-dev", - "resolved": "https://registry.npmjs.org/@aut-labs/d-aut/-/d-aut-1.0.204-dev.tgz", - "integrity": "sha512-sDEu6yyvqu/KjqobI6nBoovrHWwhA4DoXPWObQLcGRs1Isuxg/d2HhP2/9k6Xz5zjFDo/w3MDI3XDvpVos20dg==" + "version": "1.0.205-dev", + "resolved": "https://registry.npmjs.org/@aut-labs/d-aut/-/d-aut-1.0.205-dev.tgz", + "integrity": "sha512-L60dOMFM5Qp94Gbtun5C6ty+pvtXwmqR9IJf4x9LRSOOeJoOYsLu1X7YjvbMLn4fy2GSGI2/0wzl4DB8E2phqQ==" }, "node_modules/@aut-labs/sdk": { - "version": "0.0.220-dev", - "resolved": "https://registry.npmjs.org/@aut-labs/sdk/-/sdk-0.0.220-dev.tgz", - "integrity": "sha512-Y5ud38chCfVVfKwr8mEP9IP5kZUImC6V1ZkmoUGUX9fyGHdDg56OVlAr7OaJnU/IfrJDDCuQllyLVk4QZJB6Xw==", + "version": "0.0.222-dev", + "resolved": "https://registry.npmjs.org/@aut-labs/sdk/-/sdk-0.0.222-dev.tgz", + "integrity": "sha512-0RMVx8JojxsWZZkfUaMPB6y/dKqwqoG8fbMzVQ57isgX+XCfRdqAQTh6mjM32O77VLi1N1Y71x7p33Zb89a15A==", + "license": "MIT", "dependencies": { "@aut-labs/abi-types": "^0.0.86-dev", "date-fns": "^2.29.3", diff --git a/package.json b/package.json index 96d7a53..749d5aa 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,9 @@ "dependencies": { "@apollo/client": "^3.9.1", "@aut-labs/abi-types": "^0.0.86-dev", - "@aut-labs/connector": "^0.0.203", - "@aut-labs/d-aut": "^1.0.204-dev", - "@aut-labs/sdk": "^0.0.220-dev", + "@aut-labs/connector": "^0.0.205", + "@aut-labs/d-aut": "^1.0.205-dev", + "@aut-labs/sdk": "^0.0.222-dev", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", "@leenguyen/react-flip-clock-countdown": "^1.4.0", diff --git a/src/App.tsx b/src/App.tsx index f873073..82f33c8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,13 +9,13 @@ import { environment } from "@api/environment"; import { updateWalletProviderState } from "@store/WalletProvider/WalletProvider"; import { getAppConfig } from "@api/aut.api"; import AutSDK from "@aut-labs/sdk"; -import GetStarted from "./pages/GetStarted/GetStarted"; import AutLoading from "@components/AutLoading"; import { HubData } from "@store/Hub/hub.reducer"; -import ClaimRole from "./pages/DiscordBot/ClaimRole"; -import Callback from "./pages/Oauth2Callback/Callback"; const AutDashboardMain = lazy(() => import("./pages/AutDashboardMain")); +const Callback = lazy(() => import("./pages/Oauth2Callback/Callback")); +const ClaimRole = lazy(() => import("./pages/DiscordBot/ClaimRole")); +const GetStarted = lazy(() => import("./pages/GetStarted/GetStarted")); function App() { const dispatch = useAppDispatch(); @@ -24,14 +24,6 @@ function App() { const hubData = useSelector(HubData); const location = useLocation(); - // const isLoading = useMemo( - // () => !isAuthenticating && isInitialized, - // [isAuthenticating, isInitialized] - // ); - - console.log(isAuthenticating, "isAuthenticating"); - console.log(isInitialized, "isInitialized"); - // console.log(isLoading, "isLoading"); const returnUrl = useMemo(() => { if (!hubData) return "/"; const shouldGoToDashboard = @@ -40,7 +32,6 @@ function App() { const url = location.state?.from; return url || goTo; }, [hubData]); - console.log(returnUrl, "returnUrl"); useEffect(() => { getAppConfig().then(async (networks) => { @@ -49,7 +40,6 @@ function App() { networksConfig: networks }) ); - const sdk = new AutSDK({ ipfs: { apiKey: environment.ipfsApiKey, @@ -57,31 +47,10 @@ function App() { gatewayUrl: environment.ipfsGatewayUrl } }); - // await AutSDK.getInstance(true); setInitialized(true); }); - // .finally(() => setLoading(false)); }, []); - // useEffect(() => { - // getAppConfig() - // .then(async (res) => { - // dispatch(setNetworks(res)); - // const [network] = res.filter((d) => !d.disabled); - // setConfig(generateNetworkConfig(network)); - // new AutSDK({ - // ipfs: { - // apiKey: environment.ipfsApiKey, - // secretApiKey: environment.ipfsApiSecret, - // gatewayUrl: environment.ipfsGatewayUrl - // } - // }); - // }) - // .catch(() => { - // setError(true); - // }); - // }, []); - return ( <> diff --git a/src/api/aut.api.ts b/src/api/aut.api.ts index edc7de7..ebc4814 100644 --- a/src/api/aut.api.ts +++ b/src/api/aut.api.ts @@ -1,9 +1,22 @@ import axios from "axios"; import { environment } from "./environment"; import { NetworkConfig } from "./ProviderFactory/network.config"; +import { AuthSig } from "@aut-labs/connector/lib/esm/aut-sig"; export const getAppConfig = (): Promise => { return axios .get(`${environment.apiUrl}/aut/config/network/${environment.networkEnv}`) .then((r) => r.data); }; + +interface EncryptRequest { + autSig: AuthSig; + message: string; + hubAddress: string; +} + +export const encryptMessage = (body: EncryptRequest): Promise => { + return axios + .post(`${environment.apiUrl}/task/encrypt`, body) + .then((r) => r.data); +}; diff --git a/src/api/contribution-types/discord-gathering.model.ts b/src/api/contribution-types/discord-gathering.model.ts index 3bfb78b..bdd8f74 100644 --- a/src/api/contribution-types/discord-gathering.model.ts +++ b/src/api/contribution-types/discord-gathering.model.ts @@ -40,4 +40,6 @@ export class DiscordGatheringContribution< data.properties as DiscordGatheringContributionProperties ) as T; } + + contributionType? = "Discord Gatherings"; } diff --git a/src/api/contribution-types/join-discord.model.ts b/src/api/contribution-types/join-discord.model.ts index 828e0f1..489d5c3 100644 --- a/src/api/contribution-types/join-discord.model.ts +++ b/src/api/contribution-types/join-discord.model.ts @@ -35,4 +35,6 @@ export class JoinDiscordContribution< data.properties as JoinDiscordTaskContributionProperties ) as T; } + + contributionType? = "Join Discord"; } diff --git a/src/api/contribution-types/open-task.model.ts b/src/api/contribution-types/open-task.model.ts index a52b944..115ee90 100644 --- a/src/api/contribution-types/open-task.model.ts +++ b/src/api/contribution-types/open-task.model.ts @@ -39,4 +39,6 @@ export class OpenTaskContributionProperties extends TaskContributionProperties { data.properties as OpenTaskContributionProperties ) as T; } + + contributionType? = "Open Task"; } \ No newline at end of file diff --git a/src/api/contribution-types/quiz.model.model.ts b/src/api/contribution-types/quiz.model.model.ts index d3f6837..6e58513 100644 --- a/src/api/contribution-types/quiz.model.model.ts +++ b/src/api/contribution-types/quiz.model.model.ts @@ -4,19 +4,46 @@ import { TaskContributionProperties } from "@aut-labs/sdk"; +interface QuizQuestionsAndAnswers { + question: string; + questionType: string; + answers: { + value: string; + correct: boolean; + }[]; +} + export class QuizTaskContributionProperties extends TaskContributionProperties { + questions: QuizQuestionsAndAnswers[]; + hash: string; constructor(data: QuizTaskContributionProperties) { super(data); + this.questions = data.questions; + this.hash = data.hash; } } export class QuizTaskContribution< T = QuizTaskContributionProperties > extends TaskContributionNFT { + static getContributionNFT( + contribution: QuizTaskContribution + ): BaseNFTModel { + const taskContribution = new QuizTaskContribution(contribution); + return { + name: taskContribution.name, + description: taskContribution.description, + properties: { + questions: taskContribution.properties.questions, + } + } as BaseNFTModel; + } constructor(data: QuizTaskContribution = {} as QuizTaskContribution) { super(data); this.properties = new QuizTaskContributionProperties( data.properties as QuizTaskContributionProperties ) as T; } + + contributionType? = "Quiz"; } diff --git a/src/api/contribution-types/retweet.model.ts b/src/api/contribution-types/retweet.model.ts index 3680822..8e6d0f9 100644 --- a/src/api/contribution-types/retweet.model.ts +++ b/src/api/contribution-types/retweet.model.ts @@ -33,4 +33,6 @@ export class RetweetContribution< data.properties as RetweetContributionProperties ) as T; } + + contributionType? = "Retweet"; } diff --git a/src/api/contribution.model.ts b/src/api/contribution.model.ts index 08da9e0..a837359 100644 --- a/src/api/contribution.model.ts +++ b/src/api/contribution.model.ts @@ -1,4 +1,4 @@ -import { BaseNFTModel } from "@aut-labs/sdk"; +import { BaseNFTModel, TaskContributionNFT } from "@aut-labs/sdk"; import { TaskType } from "./models/task-type"; import { OpenTaskContribution } from "./contribution-types/open-task.model"; import { DiscordGatheringContribution } from "./contribution-types/discord-gathering.model"; @@ -43,7 +43,8 @@ export const ContributionFactory = ( case "DiscordPolls": case "TwitterFollow": case "TwitterComment": - throw new Error("Task type not implemented"); + // throw new Error("Task type not implemented"); + return new TaskContributionNFT(data); default: throw new Error("Task type not found"); diff --git a/src/api/contributions.api.ts b/src/api/contributions.api.ts index 88652d5..3c40d7e 100644 --- a/src/api/contributions.api.ts +++ b/src/api/contributions.api.ts @@ -10,6 +10,9 @@ import { TaskFactoryContractEventType } from "@aut-labs/abi-types"; import { DiscordGatheringContribution } from "./contribution-types/discord-gathering.model"; import { OpenTaskContribution } from "./contribution-types/open-task.model"; import { RetweetContribution } from "./contribution-types/retweet.model"; +import { QuizTaskContribution } from "./contribution-types/quiz.model.model"; +import { encryptMessage } from "./aut.api"; +import { AuthSig } from "@aut-labs/connector/lib/esm/aut-sig"; const hubServiceCache: Record = {}; @@ -46,12 +49,14 @@ const createContribution = async ( uri: uri }); - const tx = await (await taskFactory.functions.registerDescription( - { uri }, - overrides - )).wait(); + const tx = await ( + await taskFactory.functions.registerDescription({ uri }, overrides) + ).wait(); - const event = findLogEvent(tx, TaskFactoryContractEventType.RegisterDescription); + const event = findLogEvent( + tx, + TaskFactoryContractEventType.RegisterDescription + ); if (!event) { return { error: "Failed to register description" @@ -88,28 +93,69 @@ const createContribution = async ( }; const createOpenTaskContribution = async ( - openTaskContribution: OpenTaskContribution, + { + contribution, + autSig + }: { contribution: OpenTaskContribution; autSig: AuthSig }, api: BaseQueryApi ) => { - const nft = OpenTaskContribution.getContributionNFT(openTaskContribution); - return createContribution(openTaskContribution, nft, api); + const nft = OpenTaskContribution.getContributionNFT(contribution); + return createContribution(contribution, nft, api); }; const createTwitterRetweetContribution = async ( - retweetContribution: RetweetContribution, + { + contribution, + autSig + }: { contribution: RetweetContribution; autSig: AuthSig }, api: BaseQueryApi ) => { - const nft = RetweetContribution.getContributionNFT(retweetContribution); - return createContribution(retweetContribution, nft, api); + const nft = RetweetContribution.getContributionNFT(contribution); + return createContribution(contribution, nft, api); }; const createDiscordGatheringContribution = async ( - openTaskContribution: DiscordGatheringContribution, + { + contribution, + autSig + }: { contribution: DiscordGatheringContribution; autSig: AuthSig }, api: BaseQueryApi ) => { - const nft = - DiscordGatheringContribution.getContributionNFT(openTaskContribution); - return createContribution(openTaskContribution, nft, api); + const nft = DiscordGatheringContribution.getContributionNFT(contribution); + return createContribution(contribution, nft, api); +}; + +const createQuizContribution = async ( + { + contribution, + autSig + }: { contribution: QuizTaskContribution; autSig: AuthSig }, + api: BaseQueryApi +) => { + const state: any = api.getState() as any; + const questionsWithoutAnswers = []; + const questions = contribution.properties.questions; + for (let i = 0; i < questions.length; i++) { + const { question, answers } = questions[i]; + const questionWithoutAnswer = { + question, + answers: answers.map((answer) => ({ + value: answer.value + })) + }; + questionsWithoutAnswers.push(questionWithoutAnswer); + } + const hubAddress = state.hub.selectedHubAddress; + const hash = await encryptMessage({ + autSig, + message: JSON.stringify(questions), + hubAddress + }); + contribution.properties.hash = hash; + contribution.properties.questions = questionsWithoutAnswers; + + const nft = QuizTaskContribution.getContributionNFT(contribution); + return createContribution(contribution, nft, api); }; export const contributionsApi = createApi({ @@ -125,13 +171,22 @@ export const contributionsApi = createApi({ if (url === "createTwitterRetweetContribution") { return createTwitterRetweetContribution(body, api); } + if (url === "createQuizContribution") { + return createQuizContribution(body, api); + } return { data: "Test" }; }, tagTypes: ["Contributions"], endpoints: (builder) => ({ - createOpenTaskContribution: builder.mutation({ + createOpenTaskContribution: builder.mutation< + void, + { + autSig: AuthSig; + contribution: OpenTaskContribution; + } + >({ query: (body) => { return { body, @@ -141,7 +196,10 @@ export const contributionsApi = createApi({ }), createDiscordGatheringContribution: builder.mutation< void, - DiscordGatheringContribution + { + autSig: AuthSig; + contribution: DiscordGatheringContribution; + } >({ query: (body) => { return { @@ -152,7 +210,10 @@ export const contributionsApi = createApi({ }), createTwitterRetweetContribution: builder.mutation< void, - RetweetContribution + { + autSig: AuthSig; + contribution: RetweetContribution; + } >({ query: (body) => { return { @@ -160,6 +221,20 @@ export const contributionsApi = createApi({ url: "createTwitterRetweetContribution" }; } + }), + createQuizContribution: builder.mutation< + void, + { + autSig: AuthSig; + contribution: QuizTaskContribution; + } + >({ + query: (body) => { + return { + body, + url: "createQuizContribution" + }; + } }) }) }); @@ -167,5 +242,6 @@ export const contributionsApi = createApi({ export const { useCreateTwitterRetweetContributionMutation, useCreateOpenTaskContributionMutation, - useCreateDiscordGatheringContributionMutation + useCreateDiscordGatheringContributionMutation, + useCreateQuizContributionMutation } = contributionsApi; diff --git a/src/hooks/useQueryContributions.tsx b/src/hooks/useQueryContributions.tsx index 8ec1c44..2425302 100644 --- a/src/hooks/useQueryContributions.tsx +++ b/src/hooks/useQueryContributions.tsx @@ -68,8 +68,7 @@ const useQueryContributions = (props: QueryFunctionOptions = {}) => { }); const [contributions, setContributions] = useState([]); - const [loadingMetadata, setLoadingMetadata] = useState(false); - + const [loadingMetadata, setLoadingMetadata] = useState(true); useEffect(() => { if (hubData?.properties?.address && data?.contributions?.length && taskTypes.length) { diff --git a/src/index.tsx b/src/index.tsx index ae52b2c..4009013 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -37,6 +37,7 @@ root.render( diff --git a/src/pages/AutDashboardMain.tsx b/src/pages/AutDashboardMain.tsx index 7038ec0..bd6c0e8 100644 --- a/src/pages/AutDashboardMain.tsx +++ b/src/pages/AutDashboardMain.tsx @@ -3,13 +3,11 @@ import SidebarDrawer from "@components/Sidebar/Sidebar"; import Dashboard from "./Dashboard/Dashboard"; import { Suspense, memo } from "react"; import AutLoading from "@components/AutLoading"; -// import { pluginRoutes } from "./Modules/Shared/routes"; import { useSelector } from "react-redux"; import { HubData } from "@store/Hub/hub.reducer"; import Admins from "./Admins/Admins"; import Archetype from "./Archetype/Archetype"; import DAut from "./Modules/Plugins/DAut/DAut"; -import { useGetArchetypeAndStatsQuery } from "@api/hub.api"; import { styled } from "@mui/material"; import backgroundImage from "@assets/hubos/bg-aut-blue.png"; import HubEdit from "./HubEdit/HubEdit"; @@ -20,7 +18,6 @@ import { AllTasks } from "./Modules/Plugins/Task/Shared/AllTasks"; import CreateOpenTask from "./Modules/Plugins/Task/Open/CreateOpenTask"; import useQueryTaskTypes from "@hooks/useQueryTaskTypes"; import CreateGathering from "./DiscordBot/CreateGathering"; -import CreatXCommentTask from "./TwitterTasks/CreateXCommentTask"; import CreateXLikeTask from "./TwitterTasks/CreateXLikeTask"; import CreateXFollowTask from "./TwitterTasks/CreateXFollowTask"; import CreateGithubCommitTask from "./GithubTasks/CreateGithubCommitTask"; @@ -30,6 +27,7 @@ import CreateXCommentTask from "./TwitterTasks/CreateXCommentTask"; import CreatePoll from "./DiscordBot/CreatePoll"; import CreateGithubOpenPRTask from "./GithubTasks/CreateGithubOpenPRTask"; import SubmitRetweetTask from "./TwitterTasks/SubmitRetweetTask"; +import CreateQuizTask from "./Modules/Plugins/Task/Quiz/CreateQuizTask"; const AutContainer = styled("div")(() => ({ display: "flex", @@ -41,15 +39,7 @@ const AutContainer = styled("div")(() => ({ })); const AutDashboardMain = () => { - // const { data: plugins, isLoading } = useGetAllPluginDefinitionsByDAOQuery( - // null, - // { - // refetchOnMountOrArgChange: false, - // skip: false - // } - // ); const hubData = useSelector(HubData); - const { data: members, loading: isLoadingMembers } = useQueryHubMembers({ skip: !hubData?.properties?.address, variables: { @@ -63,11 +53,6 @@ const AutDashboardMain = () => { } }); - const { data: archetype } = useGetArchetypeAndStatsQuery(null, { - refetchOnMountOrArgChange: false, - skip: false - }); - const { data, loading: isLoading, @@ -78,176 +63,73 @@ const AutDashboardMain = () => { take: 1000 } }); - - console.log(archetype, "archetype"); - - // const { questOnboarding } = useGetAllPluginDefinitionsByDAOQuery(null, { - // selectFromResult: ({ data }) => ({ - // questOnboarding: (data || []).find( - // (p) => - // PluginDefinitionType.QuestOnboardingPlugin === p.pluginDefinitionId - // ) - // }) - // }); - - // const { data: onboardingProgress } = useGetOnboardingProgressQuery( - // questOnboarding?.pluginAddress, - // { - // pollingInterval: 15000, - // refetchOnMountOrArgChange: true - // } - // ); - - // const totalSubmissions = useMemo(() => { - // if (onboardingProgress?.quests) { - // return onboardingProgress?.quests.reduce((prev, curr) => { - // prev += curr.tasksAndSubmissions.submissions.length; - // return prev; - // }, 0); - // } - - // return 0; - // }, [onboardingProgress]); - - const modules = []; - const isLoadingModules = false; - - // const { data: modules, isLoading: isLoadingModules } = - // useGetAllModuleDefinitionsQuery(null, { - // refetchOnMountOrArgChange: false, - // skip: false - // }); - - // const modulesRoutes = useMemo(() => { - // const { allRoutes, menuItems } = pluginRoutes( - // plugins || [], - // modules || [], - // isAdmin, - // 0, - // "" - // ); - - // console.log(allRoutes, menuItems, "allRoutes"); - - // return { - // menuItem: { - // title: "Hub", - // icon: ManageIcon, - // route: `hub`, - // children: [ - // { - // title: "Onboard new members", - // route: "modules", - // exact: true, - // icon: StackIcon, - // children: menuItems - // }, - // { - // title: "Tasks", - // route: "tasks", - // exact: true, - // icon: StackIcon - // } - // ] - // }, - // routes: allRoutes - // }; - // }, [plugins, modules, isAdmin]); - return ( <> - {isLoadingModules ? ( - - ) : ( - - }> - - } /> - } /> - } /> - } /> - } /> - }> - - } - /> - - } - /> - } - /> - } /> - } - />{" "} - } - /> - } - /> - } /> - } - /> - } - /> - } - /> - } - /> - } /> - } - /> - {/* } /> */} - {/* {modulesRoutes?.routes?.length && ( - } - /> - )} */} - {/* } /> - {modulesRoutes.routes.map((r) => r)} + + }> + + } /> + } /> + } /> + } /> + } /> + }> + + } + /> + + } + /> + } /> + } /> + } /> + } + />{" "} + } + /> + } + /> + } /> + } + /> + } + /> + } + /> + } /> + } /> } - /> */} - - - - )} + path="submit-retweet-task" + element={} + /> + + + ); diff --git a/src/pages/DiscordBot/CreateGathering.tsx b/src/pages/DiscordBot/CreateGathering.tsx index c3b16f6..c563dd5 100644 --- a/src/pages/DiscordBot/CreateGathering.tsx +++ b/src/pages/DiscordBot/CreateGathering.tsx @@ -38,6 +38,7 @@ import { FormContainer } from "../Modules/Plugins/Task/Shared/FormContainer"; import { useQuery } from "@tanstack/react-query"; import axios from "axios"; import { DiscordGatheringContribution } from "@api/contribution-types/discord-gathering.model"; +import { useWalletConnector } from "@aut-labs/connector"; const errorTypes = { maxWords: `Words cannot be more than 6`, @@ -95,6 +96,7 @@ const fetchVoiceChannels = async (guildId: string) => { }; const CreateDiscordGathering = () => { + const { state } = useWalletConnector(); const [searchParams] = useSearchParams(); const navigate = useNavigate(); const theme = useTheme(); @@ -154,7 +156,7 @@ const CreateDiscordGathering = () => { descriptionId: "" } }); - createTask(contribution); + createTask({ contribution, autSig: state.authSig }); }; useEffect(() => { @@ -165,7 +167,6 @@ const CreateDiscordGathering = () => { } }, [isSuccess, hubData]); - return ( reset()} open={isError} message={error} /> diff --git a/src/pages/Modules/Plugins/Task/Open/CreateOpenTask.tsx b/src/pages/Modules/Plugins/Task/Open/CreateOpenTask.tsx index 3ef3022..1fb53e8 100644 --- a/src/pages/Modules/Plugins/Task/Open/CreateOpenTask.tsx +++ b/src/pages/Modules/Plugins/Task/Open/CreateOpenTask.tsx @@ -31,6 +31,7 @@ import { useCreateOpenTaskContributionMutation } from "@api/contributions.api"; import SuccessDialog from "@components/Dialog/SuccessPopup"; import SubmitDialog from "@components/Dialog/SubmitDialog"; import { OpenTaskContribution } from "@api/contribution-types/open-task.model"; +import { useWalletConnector } from "@aut-labs/connector"; const errorTypes = { maxWords: `Words cannot be more than 6`, @@ -81,6 +82,7 @@ const AttachmentTypes = [ // })); const CreateOpenTask = () => { + const { state } = useWalletConnector(); const [searchParams] = useSearchParams(); const navigate = useNavigate(); const theme = useTheme(); @@ -93,11 +95,11 @@ const CreateOpenTask = () => { startDate: new Date(), endDate: null, description: "", + weight: 0, + quantity: 1, attachmentType: "", attachmentRequired: false, - textRequired: false, - weight: 0, - quantity: 1 + textRequired: false } }); const values = watch(); @@ -125,7 +127,7 @@ const CreateOpenTask = () => { descriptionId: "" } }); - createTask(contribution); + createTask({ contribution, autSig: state.authSig }); }; useEffect(() => { diff --git a/src/pages/Modules/Plugins/Task/Open/OpenTask.tsx b/src/pages/Modules/Plugins/Task/Open/OpenTask.tsx deleted file mode 100644 index 27ccb8f..0000000 --- a/src/pages/Modules/Plugins/Task/Open/OpenTask.tsx +++ /dev/null @@ -1,861 +0,0 @@ -import AutLoading from "@components/AutLoading"; -import { base64toFile } from "@utils/to-base-64"; -import { StepperButton } from "@components/Stepper"; -import { - Box, - Card, - CardContent, - CardMedia, - Chip, - Container, - Link, - Stack, - Typography, - useTheme -} from "@mui/material"; -import { AutTextField } from "@theme/field-text-styles"; -import { memo, useEffect, useState } from "react"; -import { Controller, useForm } from "react-hook-form"; -import { useSelector } from "react-redux"; -import { useSearchParams, useParams } from "react-router-dom"; -import TaskDetails from "../Shared/TaskDetails"; -import { RequiredQueryParams } from "@api/RequiredQueryParams"; -import { taskTypes } from "../Shared/Tasks"; -import ErrorDialog from "@components/Dialog/ErrorPopup"; -import LoadingDialog from "@components/Dialog/LoadingPopup"; -import { ipfsCIDToHttpUrl } from "@api/storage.api"; -import CopyAddress from "@components/CopyAddress"; -import axios from "axios"; -import { useAccount } from "wagmi"; -import { TaskContributionNFT } from "@aut-labs/sdk"; - -interface PluginParams { - plugin: any; -} - -interface UserSubmitContentProps { - task: TaskContributionNFT; - userAddress: string; - submission?: TaskContributionNFT; - plugin: any; -} - -export const taskStatuses: any = { - // [TaskStatus.Created]: { - // label: "To Do", - // color: "info" - // }, - // [TaskStatus.Finished]: { - // label: "Approved", - // color: "success" - // }, - // [TaskStatus.Submitted]: { - // label: "Pending", - // color: "warning" - // }, - // [TaskStatus.Taken]: { - // label: "Taken", - // color: "info" - // } -}; - -const UserSubmitContent = ({ - task, - userAddress, - plugin -}: UserSubmitContentProps) => { - const [searchParams] = useSearchParams(); - const [initialized, setInitialized] = useState(false); - const { control, handleSubmit, formState, setValue } = useForm({ - mode: "onChange", - defaultValues: { - openTask: null - } - }); - - useEffect(() => { - if (!initialized && task) { - // setValue("openTask", task.submission?.description); - setInitialized(true); - } - }, [initialized, task]); - - // const [submitTask, { error, isError, isLoading, reset }] = - // useSubmitOpenTaskMutation(); - - const onSubmit = async (values) => { - submitTask({ - userAddress, - task: { - ...task, - submission: { - name: "Open task submission", - description: values.openTask, - properties: { - submitter: userAddress - } as any - } - }, - onboardingQuestAddress: searchParams.get( - RequiredQueryParams.OnboardingQuestAddress - ), - pluginAddress: plugin.pluginAddress, - pluginDefinitionId: plugin.pluginDefinitionId - }); - }; - - return ( - - reset()} open={isError} message={error} /> - - - {/* {task?.status === TaskStatus.Created || - task?.status === TaskStatus.Taken ? ( - - - - {task?.metadata?.description} - - { - return ( - - ); - }} - /> - - - ) : ( - - - {(task as any)?.status === TaskStatus.Finished && ( - - - - )} - - - - {task?.metadata?.description} - - - Task Description - - - - - - {task?.submission?.description} - - - My Submission - - - - - )} */} - - - {/* {(task?.status === TaskStatus.Created || - task?.status === TaskStatus.Taken) && ( - - )} */} - - - ); -}; - -const OwnerFinalizeContent = ({ - task, - submission, - userAddress, - plugin -}: UserSubmitContentProps) => { - const [searchParams] = useSearchParams(); - const theme = useTheme(); - const isAdmin = useSelector(IsAdmin); - - const [finalizeTask, { error, isError, isLoading, reset }] = - useFinaliseOpenTaskMutation(); - - const { isLoading: isLoadingTasks } = useGetAllTasksQuery( - { - userAddress, - isAdmin - }, - { - selectFromResult: ({ isLoading, isFetching }) => ({ - isLoading: isLoading || isFetching - }) - } - ); - - const onSubmit = async () => { - finalizeTask({ - userAddress, - isAdmin: true, - task: submission, - pluginAddress: plugin.pluginAddress, - pluginDefinitionId: plugin.pluginDefinitionId - }); - }; - - return ( - - reset()} open={isError} message={error} /> - - - - {submission && ( - - - {/* Submitter: */} - - {/* */} - - )} - - {!submission && ( - <> - - {/* {task?.properties.attachmentType === "url" && ( - - - - - URL - - - - Attachment type - - - - )} - {task?.metadata?.properties.attachmentType === "text" && ( - - - - - DOC - - - - Attachment type - - - - )} - {task?.metadata?.properties.attachmentType === "image" && ( - - - - - IMG - - - - Attachment type - - - - )} */} - - {/* - - - - Attachment type - - - - */} - - )} - - {/* {submission && ( - - {submission?.metadata?.properties.attachmentType === "url" && ( - - - - - URL - - - - Attachment type - - - - - - Open link - - - - Source - - - - )} - {submission?.metadata?.properties.attachmentType === "text" && ( - - - - - DOC - - - - Attachment type - - - - - { - const result = await axios.get( - ipfsCIDToHttpUrl( - submission?.submission?.properties["fileUri"] - ) - ); - const link = document.createElement("a"); - link.download = "attachment"; - link.href = result.data; - link.click(); - }} - > - Download Document - - - - Source - - - - )} - {submission?.metadata?.properties.attachmentType === "image" && ( - - - - - IMG - - - - Attachment type - - - - - { - window.open( - ipfsCIDToHttpUrl( - submission?.submission?.properties["fileUri"] - ), - "_blank" - ); - }} - alt="Submission Image" - /> - - - - )} - - )} */} - - {submission && ( - - - {/* {submission?.submission?.description || "No description"} */} - - - Submission description - - - )} - - - - - {/* {submission?.status === TaskStatus.Submitted && ( - - )} */} - - - ); -}; - -const OpenTask = ({ plugin }: PluginParams) => { - const [searchParams] = useSearchParams(); - const { address: userAddress } = useAccount(); - const isAdmin = useSelector(IsAdmin); - - const params = useParams(); - - const { task, submission } = useGetAllTasksQuery( - { - userAddress, - isAdmin - }, - { - selectFromResult: ({ data, isLoading, isFetching }) => ({ - isLoading: isLoading || isFetching, - submission: (data?.submissions || []).find((t) => { - const [pluginType] = location.pathname.split("/").splice(-2); - return ( - t.submitter === searchParams.get("submitter") && - t.taskId === +params?.taskId - // PluginDefinitionType[pluginType] === - // taskTypes[t.taskType].pluginType - ); - }), - task: (data?.tasks || []).find((t) => { - const [pluginType] = location.pathname.split("/").splice(-2); - return ( - t.taskId === +params?.taskId - // PluginDefinitionType[pluginType] === - // taskTypes[t.taskType].pluginType - ); - }) - }) - } - ); - - console.log(task, submission, isAdmin); - - return ( - - {task ? ( - <> - - - {!isAdmin && ( - - )} - - {isAdmin && ( - - )} - - ) : ( - - )} - - ); -}; - -export default memo(OpenTask); diff --git a/src/pages/Modules/Plugins/Task/Quiz/CreateQuizTask.tsx b/src/pages/Modules/Plugins/Task/Quiz/CreateQuizTask.tsx index 5ee0f2a..0e60a5a 100644 --- a/src/pages/Modules/Plugins/Task/Quiz/CreateQuizTask.tsx +++ b/src/pages/Modules/Plugins/Task/Quiz/CreateQuizTask.tsx @@ -1,26 +1,534 @@ -import { Container, Box, Typography } from "@mui/material"; +import { AutDatepicker, FormHelperText } from "@components/Fields"; +import { StepperButton } from "@components/Stepper"; +import { Box, Button, Stack, Typography } from "@mui/material"; +import { memo } from "react"; +import { Controller, useForm } from "react-hook-form"; +import { Link, useNavigate, useSearchParams } from "react-router-dom"; +import QuestionsAndAnswers from "./QuestionsAndAnswers"; +import ArrowBackIosNewIcon from "@mui/icons-material/ArrowBackIosNew"; -interface PluginParams { - plugin: any; -} +import { countWords } from "@utils/helpers"; +import { AutIDData, HubData } from "@store/Hub/hub.reducer"; +import { useSelector } from "react-redux"; +import { FormContainer } from "../Shared/FormContainer"; +import { addMinutes } from "date-fns"; +import { + CommitmentSliderWrapper, + StyledTextField, + TextFieldWrapper +} from "../Shared/StyledFields"; +import { AutOSSlider } from "@theme/commitment-slider-styles"; +import { useCreateQuizContributionMutation } from "@api/contributions.api"; +import { dateToUnix } from "@utils/date-format"; +import { QuizTaskContribution } from "@api/contribution-types/quiz.model.model"; +import SubmitDialog from "@components/Dialog/SubmitDialog"; +import ErrorDialog from "@components/Dialog/ErrorPopup"; +import { useWalletConnector } from "@aut-labs/connector"; + +const errorTypes = { + maxWords: `Words cannot be more than 6`, + maxNameChars: `Characters cannot be more than 24`, + maxLength: `Characters cannot be more than 257` +}; + +const endDatetime = new Date(); +addMinutes(endDatetime, 45); + +const CreateQuizTask = () => { + const { state } = useWalletConnector(); + const autID = useSelector(AutIDData); + const [searchParams] = useSearchParams(); + const navigate = useNavigate(); + const hubData = useSelector(HubData); + const { + control, + handleSubmit, + getValues, + reset: resetForm, + setValue, + watch, + formState + } = useForm({ + mode: "all", + reValidateMode: "onChange", + defaultValues: { + title: "test", + startDate: new Date(), + endDate: addMinutes(new Date(), 45), + description: "test", + weight: 4, + quantity: 2, + questions: [ + { + question: "tr", + questionType: "boolean", + answers: [ + { + value: "Yes", + correct: true + }, + { + value: "No", + correct: false + } + ] + } + ] + } + }); + + const values = watch(); + + const [createTask, { error, isError, isSuccess, isLoading, reset }] = + useCreateQuizContributionMutation(); + + const onSubmit = async () => { + const values = getValues(); + const joinedHub = autID.joinedHub(hubData.properties.address); + const contribution = new QuizTaskContribution({ + name: values.title, + description: values.description, + image: "", + properties: { + taskId: searchParams.get("taskId"), + role: +joinedHub.role, + startDate: dateToUnix(values.startDate), + endDate: dateToUnix(values.endDate), + points: values.weight, + quantity: values.quantity, + descriptionId: "", + questions: values.questions, + hash: "" + } + }); + createTask({ + contribution, + autSig: state.authSig + }); + }; + + // useEffect(() => { + // if (isSuccess) { + // navigate({ + // pathname: `/${hubData?.name}/tasks` + // }); + // } + // }, [isSuccess, hubData]); -const CreateQuizTasks = ({ plugin }: PluginParams) => { return ( - + + reset()} open={isError} message={error} /> + { + reset(); + navigate({ + pathname: `/${hubData?.name}/contributions` + }); + }} + > + - - Create Quiz tasks + + + + Quiz + + + + Test your hub’s knowledge with a series of multiple-choice + question(s). - + + + + + + Title + + countWords(v) <= 6 + } + }} + render={({ field: { name, value, onChange } }) => { + return ( + + + {6 - countWords(value)} Words left + + + } + /> + ); + }} + /> + + + + Quantity + + { + return ( + + {/* + {6 - countWords(value)} Words left + */} + + } + /> + ); + }} + /> + + + + + + Description + + { + return ( + + + {257 - (value?.length || 0)} of 257 characters left + + + } + /> + ); + }} + /> + + + + + + Weight (1-10) + + + { + return ( + + + + + {value} + + + + + // + // + // Between 1 - 10 + // + // + // } + // /> + ); + }} + /> + + + + + + + + Start date + + { + return ( + + ); + }} + /> + + + + End date + + { + return ( + + ); + }} + /> + + + + + + + + + + + + ); }; -export default CreateQuizTasks; +export default memo(CreateQuizTask); diff --git a/src/pages/Modules/Plugins/Task/Quiz/QuestionsAndAnswers.tsx b/src/pages/Modules/Plugins/Task/Quiz/QuestionsAndAnswers.tsx index 4b79bec..000dbfa 100644 --- a/src/pages/Modules/Plugins/Task/Quiz/QuestionsAndAnswers.tsx +++ b/src/pages/Modules/Plugins/Task/Quiz/QuestionsAndAnswers.tsx @@ -30,7 +30,7 @@ import { } from "react-hook-form"; import AddIcon from "@mui/icons-material/Add"; import { FormHelperText } from "@components/Fields"; -import { useState } from "react"; +import { ChangeEvent, useState } from "react"; import { SubtitleWithInfo } from "@components/SubtitleWithInfoIcon"; import DeleteIcon from "@assets/hubos/delete-icon.svg?react"; @@ -436,7 +436,7 @@ const QuestionsAndAnswers = ({ control, updateForm, getFormValues }) => { null ); - const handleClick = (event: MouseEvent) => { + const handleClick = (event) => { setAnchorEl(event.currentTarget); }; diff --git a/src/pages/Modules/Plugins/Task/Quiz/QuizTask.tsx b/src/pages/Modules/Plugins/Task/Quiz/QuizTask.tsx index 6b9c52e..127241d 100644 --- a/src/pages/Modules/Plugins/Task/Quiz/QuizTask.tsx +++ b/src/pages/Modules/Plugins/Task/Quiz/QuizTask.tsx @@ -1,4 +1,3 @@ -import { useGetAllTasksQuery } from "@api/onboarding.api"; import AutLoading from "@components/AutLoading"; import { Box, @@ -11,7 +10,7 @@ import { styled, Typography } from "@mui/material"; -import { HubData, IsAdmin } from "@store/Hub/hub.reducer"; +import { HubData } from "@store/Hub/hub.reducer"; import { memo, useEffect, useState } from "react"; import { Controller, useFieldArray, useForm, useWatch } from "react-hook-form"; import { useSelector } from "react-redux"; @@ -101,24 +100,10 @@ const Answers = memo(({ control, questionIndex, answers, isDisabled }: any) => { }); const QuizTask = ({ plugin }: PluginParams) => { - const isAdmin = useSelector(IsAdmin); const { address: userAddress } = useAccount(); const params = useParams(); const [initialized, setInitialized] = useState(false); - const { task } = useGetAllTasksQuery( - { - userAddress, - isAdmin - }, - { - selectFromResult: ({ data, isLoading, isFetching }) => ({ - isLoading: isLoading || isFetching, - task: (data?.tasks || [])[0] - }) - } - ); - const { control, setValue, watch } = useForm({ mode: "onChange", defaultValues: { diff --git a/src/pages/Modules/Plugins/Task/Quiz/QuizTasks.tsx b/src/pages/Modules/Plugins/Task/Quiz/QuizTasks.tsx deleted file mode 100644 index eb5edc6..0000000 --- a/src/pages/Modules/Plugins/Task/Quiz/QuizTasks.tsx +++ /dev/null @@ -1,505 +0,0 @@ -import ErrorDialog from "@components/Dialog/ErrorPopup"; -import LoadingDialog from "@components/Dialog/LoadingPopup"; -import { AutDatepicker, FormHelperText } from "@components/Fields"; -import { StepperButton } from "@components/Stepper"; -import { - Box, - Button, - Container, - Grid, - Slider, - Stack, - Typography -} from "@mui/material"; -import { AutTextField } from "@theme/field-text-styles"; -import { pxToRem } from "@utils/text-size"; -import { memo, useEffect, useMemo, useState } from "react"; -import { Controller, useForm } from "react-hook-form"; -import { Link, useNavigate, useSearchParams } from "react-router-dom"; -import { dateToUnix } from "@utils/date-format"; -import AddIcon from "@mui/icons-material/Add"; -import QuestionsAndAnswers from "./QuestionsAndAnswers"; -import ArrowBackIosNewIcon from "@mui/icons-material/ArrowBackIosNew"; - -import LinkWithQuery from "@components/LinkWithQuery"; -import { countWords } from "@utils/helpers"; -import { HubData } from "@store/Hub/hub.reducer"; -import { useSelector } from "react-redux"; -import { useAccount } from "wagmi"; -import { FormContainer } from "../Shared/FormContainer"; -import { addMinutes } from "date-fns"; -import { TaskContributionNFT } from "@aut-labs/sdk"; -import { TaskType } from "@api/models/task-type"; - -// import "./ScrollbarStyles.scss"; - -const errorTypes = { - maxWords: `Words cannot be more than 6`, - maxNameChars: `Characters cannot be more than 24`, - maxLength: `Characters cannot be more than 257` -}; - -interface TaskTypeParams { - taskType: TaskType; -} - -const TaskSuccess = ({ pluginId, reset }) => { - const [searchParams] = useSearchParams(); - const navigate = useNavigate(); - const hubData = useSelector(HubData); - - return ( - - - - Success! Quiz task has been created and deployed on the Blockchain 🎉 - - - - - - {searchParams.has("returnUrl") && ( - - )} - - - - ); -}; - -const endDatetime = new Date(); -addMinutes(endDatetime, 45); - -const QuizTasks = ({ taskType }: TaskTypeParams) => { - const [searchParams] = useSearchParams(); - const navigate = useNavigate(); - const { address: account } = useAccount(); - const hubData = useSelector(HubData); - const [answersSaved, setAnswersSaved] = useState(false); - const { - control, - handleSubmit, - getValues, - reset: resetForm, - setValue, - watch, - formState - } = useForm({ - mode: "all", - reValidateMode: "onChange", - defaultValues: { - title: "", - startDate: new Date(), - endDate: null, - description: "", - questions: [], - weight: 0 - } - }); - - const values = watch(); - - // const [createTask, { error, isError, isSuccess, data, isLoading, reset }] = - // useCreateQuizTaskMutation(); - - const onSubmit = async () => { - const values = getValues(); - - const questionsWithoutAnswers = []; - - for (let i = 0; i < values.questions.length; i++) { - const { question, answers } = values.questions[i]; - - const questionWithoutAnswer = { - question, - answers: answers.map((answer) => ({ - value: answer.value - })) - }; - questionsWithoutAnswers.push(questionWithoutAnswer); - } - - // createTask({ - // userAddress: account, - // isAdmin: true, - // hubAddress: hubData.properties.address, - // pluginTokenId: plugin.pluginDefinitionId, - // pluginAddress: plugin.pluginAddress, - // allQuestions: values.questions, - // task: { - // role: 1, - // weight: values.weight, - // metadata: { - // name: values.title, - // description: values.description, - // properties: { - // questions: questionsWithoutAnswers - // } - // }, - // startDate: dateToUnix(values.startDate), - // endDate: dateToUnix(values.endDate) - // } as unknown as TaskContributionNFT - // }); - }; - - // useEffect(() => { - // if (isSuccess) { - // navigate({ - // pathname: `/${hubData?.name}/tasks` - // }); - // } - // }, [isSuccess, hubData]); - - return ( - - {/* reset()} open={isError} message={error} /> - */} - - - - - - Quiz - - - - Test your hub’s knowledge with a series of multiple-choice - question(s). - - - - - - countWords(v) <= 6 - } - }} - render={({ field: { name, value, onChange } }) => { - return ( - - - {6 - countWords(value)} Words left - - - } - /> - ); - }} - /> - - - { - return ( - - - - - Weight (1-10) - - - {value} - - - - - // - // - // Between 1 - 10 - // - // - // } - // /> - ); - }} - /> - - - - - { - return ( - - ); - }} - /> - { - return ( - - ); - }} - /> - - { - return ( - - - {257 - (value?.length || 0)} of 257 characters left - - - } - /> - ); - }} - /> - - - - - - - - - - - ); -}; - -export default memo(QuizTasks); diff --git a/src/pages/Modules/Plugins/Task/Shared/AllTasks.tsx b/src/pages/Modules/Plugins/Task/Shared/AllTasks.tsx index bf81a87..0aaa101 100644 --- a/src/pages/Modules/Plugins/Task/Shared/AllTasks.tsx +++ b/src/pages/Modules/Plugins/Task/Shared/AllTasks.tsx @@ -1,136 +1,11 @@ -import { Box, Container, Stack, Typography, useTheme } from "@mui/material"; +import { Box, Container, Typography, useTheme } from "@mui/material"; import { useMemo, useState } from "react"; -// import Tasks from "../../Task/Shared/Tasks"; -import { useAccount } from "wagmi"; import AutLoading from "@components/AutLoading"; import useQueryContributions from "@hooks/useQueryContributions"; -import Tasks from "./Tasks"; -import { TaskContributionNFT } from "@aut-labs/sdk"; -import OverflowTooltip from "@components/OverflowTooltip"; import { ContributionsTable } from "./ContributionsTable"; -import { TaskStatus } from "@store/model"; -import { RetweetContributionProperties } from "@api/contribution-types/retweet.model"; -// const ContributionCard = ({ -// contribution -// }: { -// contribution: TaskContributionNFT; -// }) => { -// const theme = useTheme(); - -// return ( -// <> -// -// -// -// -// {/* -// -// */} -// - -// -// {contribution?.name} -// -// -// -// -// -// -// -// -// ); -// }; - -export const AllTasks = ({ data: taskTypes }) => { +export const AllTasks = () => { const theme = useTheme(); - const isAdmin = true; - const { address } = useAccount(); - // const { data, isLoading } = useGetAllTasksQuery( - // { - // userAddress: address, - // isAdmin - // }, - // { - // refetchOnMountOrArgChange: true - // } - // ); const { data, @@ -139,23 +14,10 @@ export const AllTasks = ({ data: taskTypes }) => { } = useQueryContributions({ variables: { skip: 0, - take: 1000, + take: 1000 } }); - //TODO: Check the type more efficiently - const updatedContributions = data?.map((item) => ({ - ...item, - contributionType: (item.properties as RetweetContributionProperties) - .tweetUrl - ? "Retweet" - : "open", - status: TaskStatus.Created - })); - // const isLoading = false; - // const data = { - // tasks: [] - // }; const [searchState, setSearchState] = useState({ title: "" }); @@ -200,7 +62,7 @@ export const AllTasks = ({ data: taskTypes }) => { mt: theme.spacing(4) }} > - + {/* ({ [`&.${tableCellClasses.head}, &.${tableCellClasses.body}`]: { @@ -49,11 +44,6 @@ const TableListItem = memo((data: any) => { const { row } = data; const theme = useTheme(); - const contributionType = useMemo( - () => formatContributionType(row?.contributionType), - [row?.contributionType] - ); - const startDate = useMemo(() => { return format( new Date(row?.properties?.startDate * 1000), @@ -100,7 +90,7 @@ const TableListItem = memo((data: any) => { }} > - {contributionType} + {row?.contributionType || 'N/A'} diff --git a/src/pages/Modules/Shared/routes.tsx b/src/pages/Modules/Shared/routes.tsx index 49afecd..78fe329 100644 --- a/src/pages/Modules/Shared/routes.tsx +++ b/src/pages/Modules/Shared/routes.tsx @@ -21,7 +21,7 @@ const CreateOpenTask = lazy( () => import("../Plugins/Task/Open/CreateOpenTask") ); -const QuizTasks = lazy(() => import("../Plugins/Task/Quiz/QuizTasks")); +const QuizTasks = lazy(() => import("../Plugins/Task/Quiz/CreateQuizTask")); const QuizTask = lazy(() => import("../Plugins/Task/Quiz/QuizTask")); const CreateQuizTask = lazy( () => import("../Plugins/Task/Quiz/CreateQuizTask") diff --git a/src/pages/TaskManager/index.tsx b/src/pages/TaskManager/index.tsx index 076f8b0..a143ec4 100644 --- a/src/pages/TaskManager/index.tsx +++ b/src/pages/TaskManager/index.tsx @@ -1,26 +1,14 @@ -import { - Box, - Button, - CircularProgress, - Container, - IconButton, - Stack, - Tooltip, - Typography, - styled -} from "@mui/material"; +import { Box, Button, Container, Typography, styled } from "@mui/material"; import { memo, useEffect, useMemo, useState } from "react"; import LoadingProgressBar from "@components/LoadingProgressBar"; import RefreshIcon from "@mui/icons-material/Refresh"; import { setTitle } from "@store/ui-reducer"; import { useAppDispatch } from "@store/store.model"; import AutLoading from "@components/AutLoading"; -import useQueryTaskTypes from "@hooks/useQueryTaskTypes"; import { ModuleDefinitionCard } from "../Modules/Shared/PluginCard"; import HubOsTabs from "@components/HubOsTabs"; import { useSelector } from "react-redux"; import { HubData } from "@store/Hub/hub.reducer"; -import { AutButton, AutOsButton } from "@components/buttons"; import { SocialVerificationCard } from "./SocialVerificationCard"; import ComingSoonCard from "./ComingSoonCard"; @@ -246,6 +234,7 @@ const TaskManager = ({ isLoading, data, refetch }) => { }; }, [data]); + console.log(filteredTasks); const tabs = useMemo(() => { if (filteredTasks && filteredTasks.otherTasks.length) { return [ diff --git a/src/pages/TwitterTasks/CreateXRetweetTask.tsx b/src/pages/TwitterTasks/CreateXRetweetTask.tsx index 45ef19a..7762587 100644 --- a/src/pages/TwitterTasks/CreateXRetweetTask.tsx +++ b/src/pages/TwitterTasks/CreateXRetweetTask.tsx @@ -40,6 +40,7 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import axios from "axios"; import { useOAuthSocials } from "@components/Oauth2/oauth2"; import { RetweetContribution } from "@api/contribution-types/retweet.model"; +import { useWalletConnector } from "@aut-labs/connector"; const errorTypes = { maxWords: `Words cannot be more than 6`, @@ -50,6 +51,7 @@ const errorTypes = { }; const CreateXRetweetTask = () => { + const { state } = useWalletConnector(); const [searchParams] = useSearchParams(); const navigate = useNavigate(); const theme = useTheme(); @@ -104,7 +106,7 @@ const CreateXRetweetTask = () => { descriptionId: "" } }); - createTask(contribution); + createTask({ contribution, autSig: state.authSig }); }; return ( diff --git a/src/utils/format-contribution-type.tsx b/src/utils/format-contribution-type.tsx deleted file mode 100644 index f88869e..0000000 --- a/src/utils/format-contribution-type.tsx +++ /dev/null @@ -1,29 +0,0 @@ -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; - } - }; - - 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; - } - }; \ No newline at end of file From 8af2471565ed259299aa2e900bfe5824041d580f Mon Sep 17 00:00:00 2001 From: AntGe Date: Wed, 20 Nov 2024 10:40:51 +0200 Subject: [PATCH 3/4] improved models --- src/api/contribution.model.ts | 44 ++- src/api/contributions.api.ts | 56 +++- src/pages/AutDashboardMain.tsx | 2 +- .../GithubTasks/CreateGithubCommitTask.tsx | 94 ++++--- ...bOpenPRTask.tsx => CreateGithubPRTask.tsx} | 255 +++++++++++++----- src/pages/TwitterTasks/CreateXRetweetTask.tsx | 2 - 6 files changed, 336 insertions(+), 117 deletions(-) rename src/pages/GithubTasks/{CreateGithubOpenPRTask.tsx => CreateGithubPRTask.tsx} (67%) diff --git a/src/api/contribution.model.ts b/src/api/contribution.model.ts index a9a6d3c..ae49757 100644 --- a/src/api/contribution.model.ts +++ b/src/api/contribution.model.ts @@ -38,10 +38,12 @@ export class RetweetContribution< export class CommitContributionProperties extends TaskContributionProperties { branch: string; repository: string; + organisation: string; constructor(data: CommitContributionProperties) { super(data); this.branch = data.branch; this.repository = data.repository; + this.organisation = data.organisation; } } @@ -57,7 +59,8 @@ export class CommitContribution< description: taskContribution.description, properties: { branch: taskContribution.properties.branch, - repository: taskContribution.properties.repository + repository: taskContribution.properties.repository, + organisation: taskContribution.properties.organisation } } as BaseNFTModel; } @@ -69,6 +72,45 @@ export class CommitContribution< } } +export class PullRequestContributionProperties extends TaskContributionProperties { + branch: string; + repository: string; + organisation: string; + constructor(data: PullRequestContributionProperties) { + super(data); + this.branch = data.branch; + this.repository = data.repository; + this.organisation = data.organisation; + } +} + +export class PullRequestContribution< + T = PullRequestContributionProperties +> extends TaskContributionNFT { + static getContributionNFT( + contribution: PullRequestContribution + ): BaseNFTModel { + const taskContribution = new PullRequestContribution(contribution); + return { + name: taskContribution.name, + description: taskContribution.description, + properties: { + branch: taskContribution.properties.branch, + repository: taskContribution.properties.repository, + organisation: taskContribution.properties.organisation + } + } as BaseNFTModel; + } + constructor( + data: PullRequestContribution = {} as PullRequestContribution + ) { + super(data); + this.properties = new PullRequestContributionProperties( + data.properties as PullRequestContributionProperties + ) as T; + } +} + export class OpenTaskContributionProperties extends TaskContributionProperties { attachmentRequired: boolean; textRequired: boolean; diff --git a/src/api/contributions.api.ts b/src/api/contributions.api.ts index bf03b88..5fa4473 100644 --- a/src/api/contributions.api.ts +++ b/src/api/contributions.api.ts @@ -7,8 +7,11 @@ import AutSDK, { } from "@aut-labs/sdk"; import { BaseQueryApi, createApi } from "@reduxjs/toolkit/query/react"; import { + CommitContribution, + CommitContributionProperties, DiscordGatheringContribution, OpenTaskContribution, + PullRequestContribution, RetweetContribution } from "./contribution.model"; import { TaskFactoryContractEventType } from "@aut-labs/abi-types"; @@ -48,13 +51,14 @@ const createContribution = async ( uri: uri }); - const tx = await (await taskFactory.functions.registerDescription( - { uri }, - overrides - )).wait(); - debugger; + const tx = await ( + await taskFactory.functions.registerDescription({ uri }, overrides) + ).wait(); - const event = findLogEvent(tx, TaskFactoryContractEventType.RegisterDescription); + const event = findLogEvent( + tx, + TaskFactoryContractEventType.RegisterDescription + ); if (!event) { return { error: "Failed to register description" @@ -115,6 +119,22 @@ const createDiscordGatheringContribution = async ( return createContribution(openTaskContribution, nft, api); }; +const createGithubCommitContribution = async ( + githubContribution: CommitContribution, + api: BaseQueryApi +) => { + const nft = CommitContribution.getContributionNFT(githubContribution); + return createContribution(githubContribution, nft, api); +}; + +const createGithubPullRequestContribution = async ( + githubContribution: PullRequestContribution, + api: BaseQueryApi +) => { + const nft = PullRequestContribution.getContributionNFT(githubContribution); + return createContribution(githubContribution, nft, api); +}; + export const contributionsApi = createApi({ reducerPath: "contributionsApi", baseQuery: (args, api, extraOptions) => { @@ -128,6 +148,12 @@ export const contributionsApi = createApi({ if (url === "createTwitterRetweetContribution") { return createTwitterRetweetContribution(body, api); } + if (url === "createGithubCommitContribution") { + return createGithubCommitContribution(body, api); + } + if (url === "createGithubPRContribution") { + return createGithubPullRequestContribution(body, api); + } return { data: "Test" }; @@ -163,11 +189,29 @@ export const contributionsApi = createApi({ url: "createTwitterRetweetContribution" }; } + }), + createGithubCommitContribution: builder.mutation({ + query: (body) => { + return { + body, + url: "createGithubCommitContribution" + }; + } + }), + createGithubPRContribution: builder.mutation({ + query: (body) => { + return { + body, + url: "createGithubPRContribution" + }; + } }) }) }); export const { + useCreateGithubPRContributionMutation, + useCreateGithubCommitContributionMutation, useCreateTwitterRetweetContributionMutation, useCreateOpenTaskContributionMutation, useCreateDiscordGatheringContributionMutation diff --git a/src/pages/AutDashboardMain.tsx b/src/pages/AutDashboardMain.tsx index 75cb330..a64224b 100644 --- a/src/pages/AutDashboardMain.tsx +++ b/src/pages/AutDashboardMain.tsx @@ -28,7 +28,7 @@ import useQueryHubMembers from "@hooks/useQueryHubMembers"; import CreateXRetweetTask from "./TwitterTasks/CreateXRetweetTask"; import CreateXCommentTask from "./TwitterTasks/CreateXCommentTask"; import CreatePoll from "./DiscordBot/CreatePoll"; -import CreateGithubOpenPRTask from "./GithubTasks/CreateGithubOpenPRTask"; +import CreateGithubOpenPRTask from "./GithubTasks/CreateGithubPRTask"; import SubmitRetweetTask from "./TwitterTasks/SubmitRetweetTask"; const AutContainer = styled("div")(() => ({ diff --git a/src/pages/GithubTasks/CreateGithubCommitTask.tsx b/src/pages/GithubTasks/CreateGithubCommitTask.tsx index f4e723d..fbc2baa 100644 --- a/src/pages/GithubTasks/CreateGithubCommitTask.tsx +++ b/src/pages/GithubTasks/CreateGithubCommitTask.tsx @@ -24,6 +24,7 @@ import { AutOSSlider } from "@theme/commitment-slider-styles"; import { AutOsButton } from "@components/buttons"; import { useCreateDiscordGatheringContributionMutation, + useCreateGithubCommitContributionMutation, useCreateOpenTaskContributionMutation } from "@api/contributions.api"; import { @@ -64,33 +65,6 @@ const AttachmentTypes = [ label: "Image" } ]; -// const StyledTextField = styled(AutTextField)(({ theme }) => ({ -// width: "100%", -// ".MuiInputBase-input": { -// fontSize: "16px", -// color: theme.palette.offWhite.main, -// "&::placeholder": { -// color: theme.palette.offWhite.main, -// opacity: 0.5 -// }, -// "&.Mui-disabled": { -// color: "#7C879D", -// textFillColor: "#7C879D" -// } -// }, -// ".MuiInputBase-root": { -// caretColor: theme.palette.primary.main, -// fieldset: { -// border: "1.5px solid #576176 !important", -// borderRadius: "6px" -// }, -// borderRadius: "6px", -// background: "transparent" -// }, -// ".MuiInputLabel-root": { -// color: "#7C879D" -// } -// })); const CreateGithubCommitTask = () => { const [searchParams] = useSearchParams(); @@ -98,6 +72,8 @@ const CreateGithubCommitTask = () => { const theme = useTheme(); const hubData = useSelector(HubData); const autID = useSelector(AutIDData); + const [createTask, { error, isError, isSuccess, isLoading, reset }] = + useCreateGithubCommitContributionMutation(); const metadata = useMemo(() => { const social = hubData.properties.socials.find((s) => s.type === "github"); @@ -116,7 +92,7 @@ const CreateGithubCommitTask = () => { repository: "", branch: "", role: null, - duration: null, + quantity: 1, allCanAttend: false, weight: 0, channelId: "" @@ -124,7 +100,6 @@ const CreateGithubCommitTask = () => { }); const values = watch(); - // Query to fetch repositories const { data: reposResponse, isLoading: loadingRepos } = useQuery({ queryKey: ["repositories", metadata.orgId], queryFn: async () => { @@ -139,7 +114,7 @@ const CreateGithubCommitTask = () => { }, enabled: !!metadata.orgId && !!metadata.orgName }); - // Query to fetch branches when a repository is selected + const { data: branchesResponse, isLoading: loadingBranches } = useQuery({ queryKey: ["branches", values.repository], queryFn: async () => { @@ -155,9 +130,7 @@ const CreateGithubCommitTask = () => { enabled: !!values.repository && !!metadata.orgName }); - const { getAuthGithub } = useOAuthSocials(); - - const onSubmit = async (data: any) => { + const onSubmit = async () => { const values = getValues(); const joinedHub = autID.joinedHub(hubData.properties.address); const contribution = new CommitContribution({ @@ -172,6 +145,7 @@ const CreateGithubCommitTask = () => { points: values.weight, branch: values.branch, repository: values.repository, + organisation: metadata.orgName, quantity: values.quantity, uri: "" } @@ -189,8 +163,8 @@ const CreateGithubCommitTask = () => { return ( - {/* reset()} open={isError} message={error} /> */} - {/* reset()} open={isError} message={error} /> + { subtitle={ isLoading ? "Creating contribution..." - : "Your submission has been created successfully!" + : "Your contribution has been created successfully!" } subtitleVariant="subtitle1" handleClose={() => { @@ -208,7 +182,7 @@ const CreateGithubCommitTask = () => { pathname: `/${hubData?.name}/contributions` }); }} - > */} + > { )} /> + + + Quantity + + { + return ( + + } + /> + ); + }} + /> + { +const CreateGithubPRTask = () => { const [searchParams] = useSearchParams(); const navigate = useNavigate(); const theme = useTheme(); const hubData = useSelector(HubData); - const autID = useSelector(AutIDData) + const autID = useSelector(AutIDData); + const [createTask, { error, isError, isSuccess, isLoading, reset }] = + useCreateGithubPRContributionMutation(); - const githubId = useMemo(() => { + const metadata = useMemo(() => { const social = hubData.properties.socials.find((s) => s.type === "github"); - return social.link; + return social.metadata; }, [hubData]); const [loading, setLoading] = useState(false); @@ -113,8 +105,10 @@ const CreateGithubOpenPRTask = () => { startDate: new Date(), endDate: null, description: "", + repository: "", + branch: "", role: null, - duration: null, + quantity: 1, allCanAttend: false, weight: 0, channelId: "" @@ -122,53 +116,56 @@ const CreateGithubOpenPRTask = () => { }); const values = watch(); - const { getAuthGithub } = useOAuthSocials(); + const { data: reposResponse, isLoading: loadingRepos } = useQuery({ + queryKey: ["repositories", metadata.orgId], + queryFn: async () => { + const response = await axios.post( + "http://localhost:4005/api/task/github/getRepositories", + { + organisationId: metadata.orgId, + organisationName: metadata.orgName + } + ); + return response.data; + }, + enabled: !!metadata.orgId && !!metadata.orgName + }); + const { data: branchesResponse, isLoading: loadingBranches } = useQuery({ + queryKey: ["branches", values.repository], + queryFn: async () => { + const response = await axios.post( + "http://localhost:4005/api/task/github/getBranches", + { + repositoryName: values.repository, + organisationName: metadata.orgName + } + ); + return response.data; + }, + enabled: !!values.repository && !!metadata.orgName + }); const onSubmit = async () => { - // const values = getValues(); - // const contribution = new DiscordGatheringContribution({ - // name: values.title, - // description: values.description, - // image: "", - // properties: { - // taskId: searchParams.get("taskId"), - // role: values.role, - // duration: values.duration, - // startDate: dateToUnix(values.startDate), - // endDate: dateToUnix(values.endDate), - // channelId: values.channelId, - // points: values.weight, - // quantity: 1, - // uri: "" - // } - // }); - // createTask(contribution); - - await getAuthGithub( - async (data) => { - debugger; - const { access_token } = data; - debugger; - setLoading(true); - // const requestModel = { - // discordAccessToken: access_token, - // hubAddress, - // authSig - // }; - // const result = await claimRole(requestModel, { - // onSuccess: (response) => { - // setLoading(false); - // setRoleClaimed(true); - // }, - // onError: (res) => { - // setLoading(false); - // } - // }); - }, - () => { - setLoading(false); + const values = getValues(); + const joinedHub = autID.joinedHub(hubData.properties.address); + const contribution = new PullRequestContribution({ + name: values.title, + description: values.description, + image: "", + properties: { + taskId: searchParams.get("taskId"), + role: +joinedHub.role, + startDate: dateToUnix(values.startDate), + endDate: dateToUnix(values.endDate), + points: values.weight, + branch: values.branch, + repository: values.repository, + organisation: metadata.orgName, + quantity: values.quantity, + uri: "" } - ); + }); + createTask(contribution); }; // useEffect(() => { @@ -181,8 +178,8 @@ const CreateGithubOpenPRTask = () => { return ( - {/* reset()} open={isError} message={error} /> */} - {/* reset()} open={isError} message={error} /> + { subtitle={ isLoading ? "Creating contribution..." - : "Your submission has been created successfully!" + : "Your contribution has been created successfully!" } subtitleVariant="subtitle1" handleClose={() => { @@ -200,7 +197,7 @@ const CreateGithubOpenPRTask = () => { pathname: `/${hubData?.name}/contributions` }); }} - > */} + > { color="offWhite.main" fontWeight="bold" > - Github Open PR Task + Github Commit Task { color="offWhite.main" fontSize="16px" > - Create a task for the community to open PRs on your Github repository. + Create a task that requires the user to commit to your hub's + repository. { }} /> + {!!reposResponse?.repositories?.length && ( + + + Repository + + ( + + + Select a repository + + {reposResponse?.repositories?.map((repo) => ( + + {repo.name} + + ))} + + )} + /> + + )} + + + + Branch + + ( + + + Select a branch + + {branchesResponse?.branches?.map((branch) => ( + + {branch.name} + + ))} + + )} + /> + + + + Quantity + + { + return ( + + } + /> + ); + }} + /> + { ); }; -export default memo(CreateGithubOpenPRTask); +export default memo(CreateGithubPRTask); diff --git a/src/pages/TwitterTasks/CreateXRetweetTask.tsx b/src/pages/TwitterTasks/CreateXRetweetTask.tsx index 551dd38..f1ac8eb 100644 --- a/src/pages/TwitterTasks/CreateXRetweetTask.tsx +++ b/src/pages/TwitterTasks/CreateXRetweetTask.tsx @@ -88,8 +88,6 @@ const CreateXRetweetTask = () => { }); const values = watch(); - const { getAuthX } = useOAuthSocials(); - const onSubmit = async () => { const values = getValues(); const joinedHub = autID.joinedHub(hubData.properties.address); From 9f77e31770889269c0f4b89fa1238927b46cf456 Mon Sep 17 00:00:00 2001 From: AntGe Date: Thu, 21 Nov 2024 00:23:38 +0200 Subject: [PATCH 4/4] returned env var usage, improved cration pages, fixes --- .../contribution-types/github-commit.model.ts | 8 + src/api/contribution-types/github-pr.model.ts | 47 +---- src/api/contribution.model.ts | 4 + src/api/contributions.api.ts | 48 +++-- src/components/Oauth2/oauth2.tsx | 4 +- src/pages/AutDashboardMain.tsx | 5 - src/pages/DiscordBot/ClaimRole.tsx | 2 +- src/pages/DiscordBot/CreateGathering.tsx | 2 +- src/pages/DiscordBot/DiscordBot.tsx | 2 +- .../GithubTasks/CreateGithubCommitTask.tsx | 11 +- src/pages/GithubTasks/CreateGithubPRTask.tsx | 19 +- .../Task/Shared/ContributionsTable.tsx | 2 +- src/pages/TwitterTasks/CreateXCommentTask.tsx | 3 +- src/pages/TwitterTasks/CreateXFollowTask.tsx | 3 +- src/pages/TwitterTasks/CreateXLikeTask.tsx | 3 +- src/pages/TwitterTasks/SubmitRetweetTask.tsx | 190 ------------------ 16 files changed, 80 insertions(+), 273 deletions(-) delete mode 100644 src/pages/TwitterTasks/SubmitRetweetTask.tsx diff --git a/src/api/contribution-types/github-commit.model.ts b/src/api/contribution-types/github-commit.model.ts index ffe51c1..4ef65cc 100644 --- a/src/api/contribution-types/github-commit.model.ts +++ b/src/api/contribution-types/github-commit.model.ts @@ -1,3 +1,9 @@ +import { + BaseNFTModel, + TaskContributionNFT, + TaskContributionProperties +} from "@aut-labs/sdk"; + export class CommitContributionProperties extends TaskContributionProperties { branch: string; repository: string; @@ -33,4 +39,6 @@ export class CommitContribution< data.properties as CommitContributionProperties ) as T; } + + contributionType? = "Commit"; } diff --git a/src/api/contribution-types/github-pr.model.ts b/src/api/contribution-types/github-pr.model.ts index d955068..8a517f1 100644 --- a/src/api/contribution-types/github-pr.model.ts +++ b/src/api/contribution-types/github-pr.model.ts @@ -1,39 +1,8 @@ -export class CommitContributionProperties extends TaskContributionProperties { - branch: string; - repository: string; - organisation: string; - constructor(data: CommitContributionProperties) { - super(data); - this.branch = data.branch; - this.repository = data.repository; - this.organisation = data.organisation; - } - } - - export class CommitContribution< - T = CommitContributionProperties - > extends TaskContributionNFT { - static getContributionNFT( - contribution: CommitContribution - ): BaseNFTModel { - const taskContribution = new CommitContribution(contribution); - return { - name: taskContribution.name, - description: taskContribution.description, - properties: { - branch: taskContribution.properties.branch, - repository: taskContribution.properties.repository, - organisation: taskContribution.properties.organisation - } - } as BaseNFTModel; - } - constructor(data: CommitContribution = {} as CommitContribution) { - super(data); - this.properties = new CommitContributionProperties( - data.properties as CommitContributionProperties - ) as T; - } - } +import { + BaseNFTModel, + TaskContributionNFT, + TaskContributionProperties + } from "@aut-labs/sdk"; export class PullRequestContributionProperties extends TaskContributionProperties { branch: string; @@ -64,12 +33,12 @@ export class CommitContributionProperties extends TaskContributionProperties { } } as BaseNFTModel; } - constructor( - data: PullRequestContribution = {} as PullRequestContribution - ) { + constructor(data: PullRequestContribution = {} as PullRequestContribution) { super(data); this.properties = new PullRequestContributionProperties( data.properties as PullRequestContributionProperties ) as T; } + + contributionType? = "Pull Request"; } \ No newline at end of file diff --git a/src/api/contribution.model.ts b/src/api/contribution.model.ts index a837359..a567523 100644 --- a/src/api/contribution.model.ts +++ b/src/api/contribution.model.ts @@ -5,6 +5,8 @@ import { DiscordGatheringContribution } from "./contribution-types/discord-gathe import { RetweetContribution } from "./contribution-types/retweet.model"; import { JoinDiscordContribution } from "./contribution-types/join-discord.model"; import { QuizTaskContribution } from "./contribution-types/quiz.model.model"; +import { CommitContribution } from "./contribution-types/github-commit.model"; +import { PullRequestContribution } from "./contribution-types/github-pr.model"; export const ContributionFactory = ( metadata: BaseNFTModel, @@ -39,7 +41,9 @@ export const ContributionFactory = ( return new QuizTaskContribution(data); case "TwitterLike": case "GitHubCommit": + return new CommitContribution(data); case "GitHubOpenPR": + return new PullRequestContribution(data); case "DiscordPolls": case "TwitterFollow": case "TwitterComment": diff --git a/src/api/contributions.api.ts b/src/api/contributions.api.ts index b7a7160..14eceea 100644 --- a/src/api/contributions.api.ts +++ b/src/api/contributions.api.ts @@ -112,6 +112,7 @@ const createTwitterRetweetContribution = async ( }: { contribution: RetweetContribution; autSig: AuthSig }, api: BaseQueryApi ) => { + debugger; const nft = RetweetContribution.getContributionNFT(contribution); return createContribution(contribution, nft, api); }; @@ -161,19 +162,26 @@ const createQuizContribution = async ( }; const createGithubCommitContribution = async ( - githubContribution: CommitContribution, + { + contribution, + autSig + }: { contribution: CommitContribution; autSig: AuthSig }, api: BaseQueryApi ) => { - const nft = CommitContribution.getContributionNFT(githubContribution); - return createContribution(githubContribution, nft, api); + debugger; + const nft = CommitContribution.getContributionNFT(contribution); + return createContribution(contribution, nft, api); }; const createGithubPullRequestContribution = async ( - githubContribution: PullRequestContribution, + { + contribution, + autSig + }: { contribution: PullRequestContribution; autSig: AuthSig }, api: BaseQueryApi ) => { - const nft = PullRequestContribution.getContributionNFT(githubContribution); - return createContribution(githubContribution, nft, api); + const nft = PullRequestContribution.getContributionNFT(contribution); + return createContribution(contribution, nft, api); }; export const contributionsApi = createApi({ @@ -246,7 +254,13 @@ export const contributionsApi = createApi({ }; } }), - createGithubCommitContribution: builder.mutation({ + createGithubCommitContribution: builder.mutation< + void, + { + autSig: AuthSig; + contribution: CommitContribution; + } + >({ query: (body) => { return { body, @@ -254,16 +268,20 @@ export const contributionsApi = createApi({ }; } }), - createGithubPRContribution: builder.mutation( + createGithubPRContribution: builder.mutation< + void, { - query: (body) => { - return { - body, - url: "createGithubPRContribution" - }; - } + autSig: AuthSig; + contribution: PullRequestContribution; } - ), + >({ + query: (body) => { + return { + body, + url: "createGithubPRContribution" + }; + } + }), createQuizContribution: builder.mutation< void, { diff --git a/src/components/Oauth2/oauth2.tsx b/src/components/Oauth2/oauth2.tsx index 9d7e95b..ca3f0a1 100644 --- a/src/components/Oauth2/oauth2.tsx +++ b/src/components/Oauth2/oauth2.tsx @@ -129,7 +129,7 @@ export const useOAuthSocials = () => { onFailure(error); } else { const response = await axios.post( - `http://localhost:4005/api/aut/config/oauth2AccessTokenDiscord`, + `${environment.apiUrl}/aut/config/oauth2AccessTokenDiscord`, { code: message.data.payload.code, callbackUrl @@ -191,7 +191,7 @@ export const useOAuthSocials = () => { } else { xCleanUp(xIntervalRef); const response = await axios.post( - `http://localhost:4005/api/aut/config/oauth2AccessTokenX`, + `${environment.apiUrl}/aut/config/oauth2AccessTokenX`, { code: message.data.payload.code, callbackUrl diff --git a/src/pages/AutDashboardMain.tsx b/src/pages/AutDashboardMain.tsx index 6910d2a..812c9a5 100644 --- a/src/pages/AutDashboardMain.tsx +++ b/src/pages/AutDashboardMain.tsx @@ -26,7 +26,6 @@ import CreateXRetweetTask from "./TwitterTasks/CreateXRetweetTask"; import CreateXCommentTask from "./TwitterTasks/CreateXCommentTask"; import CreatePoll from "./DiscordBot/CreatePoll"; import CreateGithubOpenPRTask from "./GithubTasks/CreateGithubPRTask"; -import SubmitRetweetTask from "./TwitterTasks/SubmitRetweetTask"; import CreateQuizTask from "./Modules/Plugins/Task/Quiz/CreateQuizTask"; const AutContainer = styled("div")(() => ({ @@ -123,10 +122,6 @@ const AutDashboardMain = () => { /> } /> } /> - } - /> diff --git a/src/pages/DiscordBot/ClaimRole.tsx b/src/pages/DiscordBot/ClaimRole.tsx index 0d32b66..d7057ac 100644 --- a/src/pages/DiscordBot/ClaimRole.tsx +++ b/src/pages/DiscordBot/ClaimRole.tsx @@ -40,7 +40,7 @@ const ClaimRole = () => { const { mutateAsync: claimRole } = useMutation({ mutationFn: (claimRoleRequest) => { return axios - .post(`http://localhost:4005/api/discord//get-role`, claimRoleRequest) + .post(`${environment.apiUrl}/discord//get-role`, claimRoleRequest) .then((res) => res.data); } }); diff --git a/src/pages/DiscordBot/CreateGathering.tsx b/src/pages/DiscordBot/CreateGathering.tsx index c563dd5..69fbf07 100644 --- a/src/pages/DiscordBot/CreateGathering.tsx +++ b/src/pages/DiscordBot/CreateGathering.tsx @@ -90,7 +90,7 @@ const AttachmentTypes = [ const fetchVoiceChannels = async (guildId: string) => { const response = await axios.get( - `http://localhost:4005/api/discord/guild/voiceChannels/${guildId}` + `${environment.apiUrl}/discord/guild/voiceChannels/${guildId}` ); return response.data; }; diff --git a/src/pages/DiscordBot/DiscordBot.tsx b/src/pages/DiscordBot/DiscordBot.tsx index 26e3b57..cb4928c 100644 --- a/src/pages/DiscordBot/DiscordBot.tsx +++ b/src/pages/DiscordBot/DiscordBot.tsx @@ -111,7 +111,7 @@ function DiscordBot() { } = useQuery({ queryKey: ["checkBotActive"], queryFn: () => { - return axios.get(`http://localhost:4005/api/discord/check/${guildId}`); + return axios.get(`${environment.apiUrl}/discord/check/${guildId}`); }, enabled: !!guildId }); diff --git a/src/pages/GithubTasks/CreateGithubCommitTask.tsx b/src/pages/GithubTasks/CreateGithubCommitTask.tsx index d8193d7..d604e42 100644 --- a/src/pages/GithubTasks/CreateGithubCommitTask.tsx +++ b/src/pages/GithubTasks/CreateGithubCommitTask.tsx @@ -40,6 +40,8 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import axios from "axios"; import { useOAuthSocials } from "@components/Oauth2/oauth2"; import { CommitContribution } from "@api/contribution-types/github-commit.model"; +import { useWalletConnector } from "@aut-labs/connector"; +import { environment } from "@api/environment"; const errorTypes = { maxWords: `Words cannot be more than 6`, @@ -63,6 +65,7 @@ const AttachmentTypes = [ ]; const CreateGithubCommitTask = () => { + const { state } = useWalletConnector(); const [searchParams] = useSearchParams(); const navigate = useNavigate(); const theme = useTheme(); @@ -100,7 +103,7 @@ const CreateGithubCommitTask = () => { queryKey: ["repositories", metadata.orgId], queryFn: async () => { const response = await axios.post( - "http://localhost:4005/api/task/github/getRepositories", + `${environment.apiUrl}/task/github/getRepositories`, { organisationId: metadata.orgId, organisationName: metadata.orgName @@ -115,7 +118,7 @@ const CreateGithubCommitTask = () => { queryKey: ["branches", values.repository], queryFn: async () => { const response = await axios.post( - "http://localhost:4005/api/task/github/getBranches", + `${environment.apiUrl}/task/github/getBranches`, { repositoryName: values.repository, organisationName: metadata.orgName @@ -143,10 +146,10 @@ const CreateGithubCommitTask = () => { repository: values.repository, organisation: metadata.orgName, quantity: values.quantity, - uri: "" + descriptionId: "" } }); - createTask(contribution); + createTask({ contribution, autSig: state.authSig }); }; // useEffect(() => { diff --git a/src/pages/GithubTasks/CreateGithubPRTask.tsx b/src/pages/GithubTasks/CreateGithubPRTask.tsx index a6ce54a..12184f9 100644 --- a/src/pages/GithubTasks/CreateGithubPRTask.tsx +++ b/src/pages/GithubTasks/CreateGithubPRTask.tsx @@ -1,12 +1,6 @@ import ErrorDialog from "@components/Dialog/ErrorPopup"; import { AutDatepicker, FormHelperText } from "@components/Fields"; -import { - Box, - MenuItem, - Stack, - Typography, - useTheme -} from "@mui/material"; +import { Box, MenuItem, Stack, Typography, useTheme } from "@mui/material"; import { AutSelectField } from "@theme/field-select-styles"; import { memo, useMemo, useState } from "react"; import { Controller, useForm } from "react-hook-form"; @@ -35,6 +29,8 @@ import { FormContainer } from "../Modules/Plugins/Task/Shared/FormContainer"; import { useQuery } from "@tanstack/react-query"; import axios from "axios"; import { PullRequestContribution } from "@api/contribution-types/github-pr.model"; +import { useWalletConnector } from "@aut-labs/connector"; +import { environment } from "@api/environment"; const errorTypes = { maxWords: `Words cannot be more than 6`, @@ -85,6 +81,7 @@ const AttachmentTypes = [ // })); const CreateGithubPRTask = () => { + const { state } = useWalletConnector(); const [searchParams] = useSearchParams(); const navigate = useNavigate(); const theme = useTheme(); @@ -122,7 +119,7 @@ const CreateGithubPRTask = () => { queryKey: ["repositories", metadata.orgId], queryFn: async () => { const response = await axios.post( - "http://localhost:4005/api/task/github/getRepositories", + `${environment.apiUrl}/task/github/getRepositories`, { organisationId: metadata.orgId, organisationName: metadata.orgName @@ -136,7 +133,7 @@ const CreateGithubPRTask = () => { queryKey: ["branches", values.repository], queryFn: async () => { const response = await axios.post( - "http://localhost:4005/api/task/github/getBranches", + `${environment.apiUrl}/task/github/getBranches`, { repositoryName: values.repository, organisationName: metadata.orgName @@ -164,10 +161,10 @@ const CreateGithubPRTask = () => { repository: values.repository, organisation: metadata.orgName, quantity: values.quantity, - uri: "" + descriptionId: "" } }); - createTask(contribution); + createTask({ contribution, autSig: state.authSig }); }; // useEffect(() => { diff --git a/src/pages/Modules/Plugins/Task/Shared/ContributionsTable.tsx b/src/pages/Modules/Plugins/Task/Shared/ContributionsTable.tsx index d13d4af..133700e 100644 --- a/src/pages/Modules/Plugins/Task/Shared/ContributionsTable.tsx +++ b/src/pages/Modules/Plugins/Task/Shared/ContributionsTable.tsx @@ -90,7 +90,7 @@ const TableListItem = memo((data: any) => { }} > - {row?.contributionType || 'N/A'} + {row?.contributionType || "N/A"} diff --git a/src/pages/TwitterTasks/CreateXCommentTask.tsx b/src/pages/TwitterTasks/CreateXCommentTask.tsx index caaf0fe..e177b91 100644 --- a/src/pages/TwitterTasks/CreateXCommentTask.tsx +++ b/src/pages/TwitterTasks/CreateXCommentTask.tsx @@ -38,6 +38,7 @@ import { FormContainer } from "../Modules/Plugins/Task/Shared/FormContainer"; import { useMutation, useQuery } from "@tanstack/react-query"; import axios from "axios"; import { useOAuthSocials } from "@components/Oauth2/oauth2"; +import { environment } from "@api/environment"; const errorTypes = { maxWords: `Words cannot be more than 6`, @@ -98,7 +99,7 @@ const CreateXCommentTask = () => { const { mutateAsync: verifyFollow } = useMutation({ mutationFn: (verifyFollowRequest) => { return axios - .post(`http://localhost:4005/api/task/twitter/like`, verifyFollowRequest) + .post(`${environment.apiUrl}/task/twitter/like`, verifyFollowRequest) .then((res) => res.data); } }); diff --git a/src/pages/TwitterTasks/CreateXFollowTask.tsx b/src/pages/TwitterTasks/CreateXFollowTask.tsx index 13240dd..a054585 100644 --- a/src/pages/TwitterTasks/CreateXFollowTask.tsx +++ b/src/pages/TwitterTasks/CreateXFollowTask.tsx @@ -38,6 +38,7 @@ import { FormContainer } from "../Modules/Plugins/Task/Shared/FormContainer"; import { useMutation, useQuery } from "@tanstack/react-query"; import axios from "axios"; import { useOAuthSocials } from "@components/Oauth2/oauth2"; +import { environment } from "@api/environment"; const errorTypes = { maxWords: `Words cannot be more than 6`, @@ -98,7 +99,7 @@ const CreateXFollowTask = () => { mutationFn: (verifyFollowRequest) => { return axios .post( - `http://localhost:4005/api/task/twitter/comment`, + `${environment.apiUrl}/task/twitter/comment`, verifyFollowRequest ) .then((res) => res.data); diff --git a/src/pages/TwitterTasks/CreateXLikeTask.tsx b/src/pages/TwitterTasks/CreateXLikeTask.tsx index 0bab8bb..9ae06d7 100644 --- a/src/pages/TwitterTasks/CreateXLikeTask.tsx +++ b/src/pages/TwitterTasks/CreateXLikeTask.tsx @@ -38,6 +38,7 @@ import { FormContainer } from "../Modules/Plugins/Task/Shared/FormContainer"; import { useMutation, useQuery } from "@tanstack/react-query"; import axios from "axios"; import { useOAuthSocials } from "@components/Oauth2/oauth2"; +import { environment } from "@api/environment"; const errorTypes = { maxWords: `Words cannot be more than 6`, @@ -98,7 +99,7 @@ const CreateXLikeTask = () => { mutationFn: (verifyFollowRequest) => { return axios .post( - `http://localhost:4005/api/task/twitter/like`, + `${environment.apiUrl}/task/twitter/like`, verifyFollowRequest ) .then((res) => res.data); diff --git a/src/pages/TwitterTasks/SubmitRetweetTask.tsx b/src/pages/TwitterTasks/SubmitRetweetTask.tsx deleted file mode 100644 index f12a5aa..0000000 --- a/src/pages/TwitterTasks/SubmitRetweetTask.tsx +++ /dev/null @@ -1,190 +0,0 @@ -import ErrorDialog from "@components/Dialog/ErrorPopup"; -import LoadingDialog from "@components/Dialog/LoadingPopup"; -import { AutDatepicker, FormHelperText } from "@components/Fields"; -import { - Box, - Checkbox, - duration, - FormControlLabel, - MenuItem, - Stack, - Typography, - useTheme -} from "@mui/material"; -import { AutSelectField } from "@theme/field-select-styles"; -import { memo, useEffect, useMemo, useState } from "react"; -import { Controller, useForm } from "react-hook-form"; -import { useNavigate, useSearchParams } from "react-router-dom"; -import { dateToUnix } from "@utils/date-format"; -import { countWords } from "@utils/helpers"; -import { AutIDData, HubData } from "@store/Hub/hub.reducer"; -import { useSelector } from "react-redux"; - -import { AutOSSlider } from "@theme/commitment-slider-styles"; -import { AutOsButton } from "@components/buttons"; -import { - useCreateDiscordGatheringContributionMutation, - useCreateOpenTaskContributionMutation, - useCreateTwitterRetweetContributionMutation -} from "@api/contributions.api"; -import SuccessDialog from "@components/Dialog/SuccessPopup"; -import SubmitDialog from "@components/Dialog/SubmitDialog"; -import { - CommitmentSliderWrapper, - SliderFieldWrapper, - StyledTextField, - TextFieldWrapper -} from "../Modules/Plugins/Task/Shared/StyledFields"; -import { FormContainer } from "../Modules/Plugins/Task/Shared/FormContainer"; -import { useMutation, useQuery } from "@tanstack/react-query"; -import axios from "axios"; -import { useOAuthSocials } from "@components/Oauth2/oauth2"; - -const errorTypes = { - maxWords: `Words cannot be more than 6`, - maxNameChars: `Characters cannot be more than 24`, - maxLength: `Characters cannot be more than 257`, - invalidTweetUrl: - "Please enter a valid tweet URL (e.g., https://twitter.com/username/status/123456789 or https://x.com/username/status/123456789)" -}; - -const SubmitRetweetTask = () => { - const [searchParams] = useSearchParams(); - const navigate = useNavigate(); - const theme = useTheme(); - const hubData = useSelector(HubData); - const autID = useSelector(AutIDData); - - const { mutateAsync: verifyTetweetTask } = useMutation({ - mutationFn: (verifyRetweetRequest) => { - return axios - .post( - `http://localhost:4005/api/task/twitter/retweet`, - verifyRetweetRequest - ) - .then((res) => res.data); - } - }); - - const twitterId = useMemo(() => { - const social = hubData.properties.socials.find((s) => s.type === "twitter"); - return social.link; - }, [hubData]); - - const [loading, setLoading] = useState(false); - - const { getAuthX } = useOAuthSocials(); - - const onSubmit = async () => { - await getAuthX( - async (data) => { - const { access_token } = data; - debugger; - setLoading(true); - const contributionId = "test"; - await verifyTetweetTask( - { accessToken: access_token, contributionId }, - { - onSuccess: (response) => { - debugger; - setLoading(false); - }, - onError: (res) => {} - } - ); - // const requestModel = { - // discordAccessToken: access_token, - // hubAddress, - // authSig - // }; - // const result = await claimRole(requestModel, { - // onSuccess: (response) => { - // setLoading(false); - // setRoleClaimed(true); - // }, - // onError: (res) => { - // setLoading(false); - // } - // }); - }, - () => { - setLoading(false); - } - ); - }; - - return ( - - - - Retweet Task - - - - Login with X to verify your retweet. - - - - onSubmit()} - variant="outlined" - sx={{ - width: "100px" - }} - > - - Submit Task - - - - - ); -}; - -export default memo(SubmitRetweetTask);