Skip to content

Commit

Permalink
Merge branch 'main' into fix-tag-action
Browse files Browse the repository at this point in the history
  • Loading branch information
ailisp authored Dec 1, 2023
2 parents 2d603bc + 536b4f5 commit b3a15f5
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 19 deletions.
36 changes: 32 additions & 4 deletions src/devhub/components/molecule/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ const TextInput = ({
? type
: "text";

const isValid = () => {
if (!value || value.length === 0) {
return !inputProps.required;
} else if (inputProps.min && inputProps.min > value?.length) {
return false;
} else if (inputProps.max && inputProps.max < value?.length) {
return false;
} else if (
inputProps.allowCommaAndSpace === false &&
/^[^,\s]*$/.test(value) === false
) {
return false;
} else if (
inputProps.validUrl === true &&
/^(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/.test(
value
) === false
) {
return false;
}
return true;
};

const renderedLabels = [
(label?.length ?? 0) > 0 ? (
<span className="d-inline-flex gap-1 text-wrap">
Expand All @@ -36,17 +59,20 @@ const TextInput = ({

format === "comma-separated" ? (
<span
className="d-inline-flex align-items-center text-muted"
className={`d-inline-flex align-items-center ${
isValid() ? "text-muted" : "text-danger"
}`}
style={{ fontSize: 12 }}
>
{format}
</span>
) : null,

(inputProps.max ?? null) !== null ? (
<span className="d-inline-flex text-muted" style={{ fontSize: 12 }}>{`${
value?.length ?? 0
} / ${inputProps.max}`}</span>
<span
className={`d-inline-flex ${isValid() ? "text-muted" : "text-danger"}`}
style={{ fontSize: 12 }}
>{`${value?.length ?? 0} / ${inputProps.max}`}</span>
) : null,
].filter((label) => label !== null);

Expand Down Expand Up @@ -81,6 +107,7 @@ const TextInput = ({
" "
)}
type={typeAttribute}
maxLength={inputProps.max}
{...{ onChange, placeholder, value, ...inputProps }}
/>
</div>
Expand All @@ -94,6 +121,7 @@ const TextInput = ({
}
style={{ resize: inputProps.resize ?? "vertical" }}
type={typeAttribute}
maxLength={inputProps.max}
{...{ onChange, placeholder, value, ...inputProps }}
/>
)}
Expand Down
40 changes: 37 additions & 3 deletions src/devhub/components/organism/Configurator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,49 @@ const Configurator = ({
? toFormatted(form.values)
: form.values;

const isFormValid = isValid ? isValid(formFormattedValues) : true;
const internalValidation = () =>
Object.keys(schema).every((key) => {
const fieldDefinition = schema[key];
const value = form.values[key];
if (!value || value.length === 0) {
return !fieldDefinition.inputProps.required;
} else if (
fieldDefinition.inputProps.min &&
fieldDefinition.inputProps.min > value?.length
) {
return false;
} else if (
fieldDefinition.inputProps.max &&
fieldDefinition.inputProps.max < value?.length
) {
return false;
} else if (
fieldDefinition.inputProps.allowCommaAndSpace === false &&
/^[^,\s]*$/.test(value) === false
) {
return false;
} else if (
fieldDefinition.inputProps.validUrl === true &&
/^(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/.test(
value
) === false
) {
return false;
}
return true;
});

const isFormValid = () => {
return internalValidation() && (!isValid || isValid(formFormattedValues));
};

const onCancelClick = () => {
form.reset();
if (onCancel) onCancel();
};

const onSubmitClick = () => {
if (onSubmit && isFormValid) {
if (onSubmit && isFormValid()) {
onSubmit(formFormattedValues);
}
};
Expand Down Expand Up @@ -298,7 +332,7 @@ const Configurator = ({
src={"${REPL_DEVHUB}/widget/devhub.components.molecule.Button"}
props={{
classNames: { root: classNames.submit || "btn-success" },
disabled: !form.hasUnsubmittedChanges || !isFormValid,
disabled: !form.hasUnsubmittedChanges || !isFormValid(),
icon: submitIcon || {
type: "bootstrap_icon",
variant: "bi-check-circle-fill",
Expand Down
5 changes: 2 additions & 3 deletions src/devhub/entity/community/Spawner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ const CommunityInputsPartialSchema = {
inputProps: {
min: 2,
max: 40,

allowCommaAndSpace: false,
placeholder:
"Choose unique URL handle for your community. Example: zero-knowledge.",

required: true,
},

Expand All @@ -38,7 +37,7 @@ const CommunityInputsPartialSchema = {
inputProps: {
min: 2,
max: 30,

allowCommaAndSpace: false,
placeholder:
"Any posts with this tag will show up in your community feed.",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CommunityAboutSchema = {

placeholder:
"Tell people about your community. This will appear on your community’s homepage.",

required: true,
resize: "none",
},

Expand Down Expand Up @@ -37,7 +37,7 @@ const CommunityAboutSchema = {
},

website_url: {
inputProps: { prefix: "https://", min: 2, max: 60 },
inputProps: { prefix: "https://", min: 2, max: 60, validUrl: true },
label: "Website",
order: 5,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CommunityInformationSchema = {
inputProps: {
min: 2,
max: 40,

allowCommaAndSpace: false,
placeholder:
"Choose unique URL handle for your community. Example: zero-knowledge.",

Expand All @@ -45,7 +45,7 @@ const CommunityInformationSchema = {
inputProps: {
min: 2,
max: 30,

allowCommaAndSpace: false,
placeholder:
"Any posts with this tag will show up in your community feed.",

Expand Down
27 changes: 24 additions & 3 deletions src/devhub/entity/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,25 @@ const toggleEditor = () => {
State.update({ showEditor: !state.showEditor });
};

let amount = null;
let token = null;
let supervisor = null;

if (state.postType === "Solution") {
const amountMatch = post.snapshot.description.match(
/Requested amount: (\d+(\.\d+)?) (\w+)/
);
amount = amountMatch ? parseFloat(amountMatch[1]) : null;
token = amountMatch ? amountMatch[3] : null;

const sponsorMatch = post.snapshot.description.match(
/Requested sponsor: @([^\s]+)/
);
supervisor = sponsorMatch ? sponsorMatch[1] : null;
}

const seekingFunding = amount !== null || token !== null || supervisor !== null;

function Editor() {
return (
<div class="row" id={`accordion${postId}`} key="editors-footer">
Expand Down Expand Up @@ -595,9 +614,11 @@ function Editor() {
labels: post.snapshot.labels,
name: post.snapshot.name,
description: post.snapshot.description,
amount: post.snapshot.amount,
token: tokenResolver(post.snapshot.sponsorship_token),
supervisor: post.snapshot.supervisor,
amount: post.snapshot.amount || amount,
token: tokenResolver(post.snapshot.sponsorship_token || token),
supervisor:
post.snapshot.post.snapshot.supervisor || supervisor,
seekingFunding: seekingFunding,
githubLink: post.snapshot.github_link,
onDraftStateChange,
draftState:
Expand Down
14 changes: 12 additions & 2 deletions src/devhub/entity/post/PostEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ const labels = labelStrings.map((s) => {
return { name: s };
});

const cleanDescription = (description) => {
return description.replace(
/###### Requested amount: .+?\n###### Requested sponsor: @[^\s]+\n/g,
""
);
};

initState({
seekingFunding: false,
seekingFunding: props.seekingFunding ?? false,
author_id: context.accountId,
// Should be a list of objects with field "name".
labels,
Expand All @@ -52,7 +59,10 @@ initState({
labelStrings,
postType,
name: props.name ?? "",
description: props.description ?? "",
description:
(props.postType === "Solution"
? cleanDescription(props.description)
: props.description) ?? "",
amount: props.amount ?? "0",
token: props.token ?? "USDT",
supervisor: props.supervisor ?? "neardevdao.near",
Expand Down
1 change: 1 addition & 0 deletions src/devhub/page/post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { id } = props;
const Container = styled.div`
padding: 0 3rem 3rem 3rem;
width: 100%;
max-width: 100%;
@media screen and (max-width: 768px) {
padding: 0 1rem 1rem 1rem;
Expand Down

0 comments on commit b3a15f5

Please sign in to comment.