Skip to content

Commit

Permalink
Merge pull request #88 from PotLock/staging
Browse files Browse the repository at this point in the history
Staging => main
  • Loading branch information
M-Rb3 authored May 11, 2024
2 parents fdc972e + 36af4d2 commit 88028be
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 40 deletions.
8 changes: 1 addition & 7 deletions src/components/Inputs/SelectMultiple/SelectMultiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ const SelectMultiple = (props: Props) => {
return (
<Container>
{label && <Label>{label}</Label>}
<Typeahead
options={options}
multiple
onChange={onChange}
placeholder={placeholder}
// selected={selected}
/>
<Typeahead options={options} multiple onChange={onChange} placeholder={placeholder} selected={selected} />
</Container>
);
};
Expand Down
33 changes: 8 additions & 25 deletions src/pages/CreateProject/components/CreateForm/CreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import validateGithubRepoUrl from "@app/utils/validateGithubRepoUrl";
import validateNearAddress from "@app/utils/validateNearAddress";
import { socialFields, CATEGORY_MAPPINGS, CHAIN_OPTIONS, DEFAULT_STATE } from "../../utils/fields";
import handleCreateOrUpdateProject from "../../utils/handleCreateOrUpdateProject";
import { projectDisabled } from "../../utils/helpers";
import { extractRepoPath, projectDisabled } from "../../utils/helpers";
import setSocialData from "../../utils/setSocialData";
import AccountsStack from "../AccountsStack/AccountsStack";
import DAOInProgress from "../DAOInProgress/DAOInProgress";
Expand Down Expand Up @@ -621,30 +621,13 @@ const CreateForm = (props: { edit: boolean }) => {
// validate link
const repo = state.githubRepos[index];

const isValid =
validateGithubRepoUrl(repo.value) || repo.value === "" || repo.value === undefined;
// if invalid, set the error as the 2nd element of the array
if (!isValid) {
State.update({
githubRepos: {
...state.githubRepos,
[index]: {
value: repo.value,
err: "Invalid GitHub Repo URL",
},
},
});
} else {
State.update({
githubRepos: {
...state.githubRepos,
[index]: {
value: repo.value,
err: "",
},
},
});
}
const repoObj = extractRepoPath(repo.value);
State.update({
githubRepos: {
...state.githubRepos,
[index]: repoObj,
},
});
},
error: state.githubRepos[index].err || "",
}}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/CreateProject/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const Header = ({ edit }: { edit: boolean }) => {
>
<HeaderTitle>{edit ? "Edit" : "Register New"} Project</HeaderTitle>
<HeaderDescription>
Create a profile for your impact project to receive direct donations, Qualify for funding rounds, join NEAR's
accelerator, and get discovered across social platforms.
Create a profile for your project to receive donations and qualify for funding rounds.
</HeaderDescription>
</HeaderContainer>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/CreateProject/utils/getSocialData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getSocialData = () => {
plSmartContracts: formattedSmartContracts ? JSON.stringify(formattedSmartContracts) : null,
plGithubRepos: JSON.stringify(
Object.values(state.githubRepos)
.map(({ value, err }: any) => (err ? false : value))
.map(({ value, err }: any) => (err ? false : "github.com/" + value))
.filter((val: any) => val),
),
plFundingSources: JSON.stringify(state.fundingSources),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const handleCreateOrUpdateProject = (e: any) => {
return;
}
const socialData = getSocialData();

if (state.backgroundImage) {
socialData.profile.backgroundImage = state.backgroundImage;
}
Expand Down
24 changes: 24 additions & 0 deletions src/pages/CreateProject/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,27 @@ export const projectDisabled = () =>
(state.hasReceivedFunding && !state.fundingSources.length) ||
!state.categories.length ||
state.categoriesError;

export function extractRepoPath(url: string) {
if (url) {
// Define a regular expression pattern to match GitHub repository URLs
const pattern = /^(?:https?:\/\/)?(?:www\.)?github\.com\/([^\/]+\/[^\/]+(?:\/.*)?)\/?$/;
// Execute the regular expression on the URL
const match = url.match(pattern);
// If a match is found, return the extracted repository path; otherwise, return null
return match
? {
value: match[1],
err: "",
}
: {
value: url,
err: "",
};
} else {
return {
value: "",
err: "",
};
}
}
19 changes: 15 additions & 4 deletions src/pages/CreateProject/utils/setSocialData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Near, State } from "alem";
import getTeamMembersFromSocialProfileData from "@app/utils/getTeamMembersFromSocialProfileData";
import { CATEGORY_MAPPINGS } from "./fields";
import { extractRepoPath } from "./helpers";

interface GithubRepos {
[idx: string]: { value: string; err: string };
}

const setSocialData = (accountId: string, shouldSetTeamMembers?: any) => {
Near.asyncView("social.near", "get", { keys: [`${accountId}/**`] })
Expand All @@ -26,6 +31,7 @@ const setSocialData = (accountId: string, shouldSetTeamMembers?: any) => {
const description = profileData.description || "";
const publicGoodReason = profileData.plPublicGoodReason || "";
let categories = [];

if (profileData.plCategories) {
categories = JSON.parse(profileData.plCategories);
} else if (profileData.category) {
Expand Down Expand Up @@ -53,11 +59,16 @@ const setSocialData = (accountId: string, shouldSetTeamMembers?: any) => {
const hasSmartContracts = smartContracts.length > 0;
smartContracts.push(["", ""]); // Add an empty string to the end of the array to allow for adding new contracts

const githubRepos = profileData.plGithubRepos
? JSON.parse(profileData.plGithubRepos).map((repo: any) => [repo])
: [];
const githubRepos: GithubRepos = {};

if (profileData.plGithubRepos) {
JSON.parse(profileData.plGithubRepos).forEach((repo: string, idx: string) => {
githubRepos[idx] = extractRepoPath(repo);
});
}

const originalGithubRepos = githubRepos;
githubRepos.push([""]); // Add an empty string to the end of the array to allow for adding new repos
// githubRepos.push([""]); // Add an empty string to the end of the array to allow for adding new repos

const fundingSources = profileData.plFundingSources ? JSON.parse(profileData.plFundingSources) : [];
const hasReceivedFunding = fundingSources.length > 0;
Expand Down
12 changes: 11 additions & 1 deletion src/pages/Project/NavPages/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ const About = ({ projectId, accountId }: Props) => {

const githubRepos = profile.plGithubRepos ? JSON.parse(profile.plGithubRepos) : [];

function convertToGitHubURL(path: string) {
const prefix = "https://github.com/";
// If the path starts with "github.com/", return it as it is
if (path.startsWith("github.com/")) {
return `https://${path}`;
}
// If the path does not contain "github.com/", assume it's a repository path and prepend the prefix
return `${prefix}${path}`;
}

const Github = () =>
githubRepos.length > 0 ? (
<GithubWrapper>
{githubRepos.map((url: string) => (
<a href={url} target="_blank">
<a href={convertToGitHubURL(url)} target="_blank">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.5 0.5V2.5H10.09L0.5 12.09L1.91 13.5L11.5 3.91V12.5H13.5V0.5H1.5Z" fill="#7B7B7B" />
</svg>
Expand Down

0 comments on commit 88028be

Please sign in to comment.