Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: frontend borrower monthly income 34 & build errors #42

Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@radix-ui/react-toast": "^1.2.4",
"@radix-ui/react-tooltip": "^1.1.6",
"@shadcn/ui": "^0.0.4",
"@types/recharts": "^1.8.29",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"i18next": "^24.2.2",
Expand All @@ -37,6 +38,7 @@
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.2",
"react-i18next": "^15.4.1",
"recharts": "^2.15.1",
"tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.24.1",
Expand Down
16 changes: 9 additions & 7 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ export default function HomePage() {
root.classList.add(theme);
}, [theme]);


useEffect(() => {
if (address) {
useEffect(() => {
if (address) {
const role = localStorage.getItem("userRole");
if (role) {
setStoredRole(role);
registerUserBeforeRedirect(address, role);
} else if (!role) {
//fetchUserRole(address); // API Request
setRole("lender"); // for test
console.log("No role found, setting default role: lender");
// Temporarily using default role. Will use fetchUserRole when API is ready
setRole("lender"); // for test
console.log("No role found, setting default role: lender");
}
}
}, [role, setRole]);
}, [address, setRole]);

console.log("ROL EN HOMEPAGE:", role);

Expand All @@ -71,6 +71,7 @@ export default function HomePage() {
}
}, [address, role, router]);

// fetchUserRole is temporarily disabled but will be used for API integration
const fetchUserRole = async (walletAddress: string) => {
try {
const response = await fetch(`/users/role?wallet_address=${walletAddress}`);
Expand Down Expand Up @@ -164,6 +165,7 @@ export default function HomePage() {
{/* Test button*/}
<div className="flex justify-center my-4">
<button
type="button"
onClick={clearRole}
className="px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600 transition"
>
Expand Down
35 changes: 33 additions & 2 deletions src/components/dashboard/settings/AccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { AccountFormValues } from "@/hooks/use-settings";
import { UseFormReturn } from "react-hook-form";
import type { AccountFormValues } from "@/hooks/use-settings";
import type { UseFormReturn } from "react-hook-form";
import { useAuthStore } from "@/app/page";

interface AccountFormProps {
form: UseFormReturn<AccountFormValues>;
Expand All @@ -27,6 +28,8 @@ interface AccountFormProps {

export function AccountForm({ form, onSubmit }: AccountFormProps) {
const { t } = useTranslation();
const { role } = useAuthStore();
const isBorrower = role?.toLowerCase() === "borrower";

return (
<Form {...form}>
Expand Down Expand Up @@ -93,6 +96,34 @@ export function AccountForm({ form, onSubmit }: AccountFormProps) {
</FormItem>
)}
/>
{isBorrower && (
<FormField
control={form.control}
name="monthlyIncome"
render={({ field }) => (
<FormItem>
<FormLabel>{t("settings.account.monthlyIncome.label")}</FormLabel>
<FormControl>
<Input
type="number"
placeholder={t("settings.account.monthlyIncome.placeholder")}
{...field}
onChange={(e) => {
const value = e.target.value ? Number.parseFloat(e.target.value) : undefined;
field.onChange(value);
}}
value={field.value || ""}
className="[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
/>
</FormControl>
<FormDescription>
{t("settings.account.monthlyIncome.description")}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
)}
<Button type="submit">{t("settings.account.submit")}</Button>
</form>
</Form>
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/use-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const accountFormSchema = z.object({
language: z.string({
required_error: "Please select a language.",
}),
monthlyIncome: z.number().optional().refine((val) => !val || val >= 0, {
message: "Monthly income must be a positive number",
}),
});

const notificationsFormSchema = z.object({
Expand Down Expand Up @@ -86,6 +89,7 @@ export function useSettingsForm() {
name: "",
dob: "",
language: "",
monthlyIncome: undefined,
},
mode: "onChange",
});
Expand Down
57 changes: 31 additions & 26 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@
"es": "Spanish"
}
},
"monthlyIncome": {
"label": "Monthly Income",
"placeholder": "Enter your monthly income",
"description": "Your average monthly income in USD"
},
"submit": "Update Account"
}
},
Expand Down Expand Up @@ -166,7 +171,7 @@
},
"searchBar": {
"placeholder": "Search by Borrower or Loan ID"
}
},
"auth": {
"common": {
"emailLabel": "Email Address",
Expand Down Expand Up @@ -199,30 +204,30 @@
"successMessage": "Reset instructions have been sent to your email address."
}
},
"loanRequests": {
"title": "Loan Requests",
"subtitle": "All Loan Requests",
"description": "A list of all loan requests from borrowers. Review and take action.",
"table": {
"requestId": "Request ID",
"borrower": "Borrower",
"amount": "Amount ($)",
"purpose": "Purpose",
"creditScore": "Credit Score",
"status": "Status",
"actions": "Actions"
}
},
"status": {
"allStatuses": "All Statuses",
"pending": "Pending",
"under_review": "Under Review",
"approved": "Approved"
},
"actions": {
"viewDetails": "View details",
"approveRequest": "Approve request",
"rejectRequest": "Reject request",
"contactBorrower": "Contact borrower"
"loanRequests": {
"title": "Loan Requests",
"subtitle": "All Loan Requests",
"description": "A list of all loan requests from borrowers. Review and take action.",
"table": {
"requestId": "Request ID",
"borrower": "Borrower",
"amount": "Amount ($)",
"purpose": "Purpose",
"creditScore": "Credit Score",
"status": "Status",
"actions": "Actions"
}
},
"status": {
"allStatuses": "All Statuses",
"pending": "Pending",
"under_review": "Under Review",
"approved": "Approved"
},
"actions": {
"viewDetails": "View details",
"approveRequest": "Approve request",
"rejectRequest": "Reject request",
"contactBorrower": "Contact borrower"
}
}