Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Add React hook form validations #9835

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions components/form/Textarea.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { forwardRef } from "react";
import Label from "./Label";

export default function Textarea({ name, value, label, ...restProps }) {
const Textarea = forwardRef(({ name, value, label, ...restProps },ref) => {
ChinmayMhatre marked this conversation as resolved.
Show resolved Hide resolved
return (
<div>
<Label htmlFor={name}>{label}</Label>
<textarea
ref={ref}
rows={4}
name={name}
id={name}
Expand All @@ -14,4 +16,6 @@ export default function Textarea({ name, value, label, ...restProps }) {
/>
</div>
);
}
})

ChinmayMhatre marked this conversation as resolved.
Show resolved Hide resolved
export default Textarea;
17 changes: 8 additions & 9 deletions components/user/UserMilestone.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import Edit from "@components/account/manage/Edit";
import Markdown from "@components/Markdown";
import { shortenDate } from "@services/utils/dateFormat";

export default function UserMilestone({ milestone, isGoal, manage }) {
export default function UserMilestone({ milestone, manage }) {
const [date, setDate] = useState(milestone.date);

useEffect(() => {
if (milestone.date) {
const formattedDate = shortenDate({
Expand All @@ -22,11 +21,10 @@ export default function UserMilestone({ milestone, isGoal, manage }) {
}, [milestone.date, milestone.dateFormat]);

const DisplayIcon = getIcon(milestone.icon);
const item = (milestone, isGoal) => {
const colors = isGoal
const item = () => {
const colors = milestone.isGoal
? "text-primary-medium/70 dark:text-primary-low-medium/[.83]"
: "text-primary-medium dark:text-primary-low-medium";

return (
<div className="flex space-x-3 grow">
{milestone.icon && (
Expand All @@ -38,7 +36,7 @@ export default function UserMilestone({ milestone, isGoal, manage }) {
<div className="flex items-center justify-between">
<h2
className={classNames(
isGoal && "opacity-70",
milestone.isGoal && "opacity-70",
"text-sm font-medium",
)}
>
Expand All @@ -65,17 +63,18 @@ export default function UserMilestone({ milestone, isGoal, manage }) {
);
};

const edit = (milestone, isGoal) => (
const edit = () => (
<Edit
href={`/account/manage/milestone/${milestone._id}`}
label={`${milestone.title} Milestone`}
>
{item(milestone, isGoal)}
{item(milestone.isGoal)}
</Edit>
);

return (
<li className="flex flex-row gap-8 py-4 border-primary-low-medium">
{manage ? edit(milestone, isGoal) : item(milestone, isGoal)}
{manage ? edit() : item()}
</li>
);
}
2 changes: 0 additions & 2 deletions components/user/UserMilestones.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default function UserMilestones({ milestones, manage = false }) {
historicMilestones.map((milestone, key) => (
<UserMilestone
milestone={milestone}
isGoal={false}
key={key}
manage={manage}
/>
Expand All @@ -34,7 +33,6 @@ export default function UserMilestones({ milestones, manage = false }) {
{futureMilestones.map((goal, key) => (
<UserMilestone
milestone={goal}
isGoal={true}
key={key}
manage={manage}
/>
Expand Down
27 changes: 26 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"@headlessui/react": "^1.7.17",
"@heroicons/react": "^2.0.18",
"@hookform/resolvers": "^3.3.2",
"@mdx-js/loader": "^3.0.0",
"@mdx-js/react": "^3.0.0",
"@next/mdx": "^14.0.1",
Expand All @@ -35,6 +36,7 @@
"react": "^18.2.0",
"react-children-utilities": "^2.9.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.48.2",
"react-icons": "^4.11.0",
"react-leaflet": "^4.2.1",
"react-markdown": "^9.0.0",
Expand Down
Loading
Loading