Skip to content

Commit

Permalink
Merge pull request #343 from captableinc/fix/bugs
Browse files Browse the repository at this point in the history
fix: some bugs and linting issues
  • Loading branch information
dahal authored May 21, 2024
2 parents d1807a4 + 99ef1e6 commit 2fec54a
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import StakeholderTable from "@/components/stakeholder/stakeholder-table";
import { Card } from "@/components/ui/card";
import { api } from "@/trpc/server";
import { RiGroup2Fill } from "@remixicon/react";
import { type Metadata } from "next";
import type { Metadata } from "next";

export const metadata: Metadata = {
title: "Stakeholders",
Expand All @@ -13,7 +13,7 @@ export const metadata: Metadata = {
const StakeholdersPage = async () => {
const stakeholders = await api.stakeholder.getStakeholders.query();

if (stakeholders.data.length === 0) {
if (stakeholders.length === 0) {
return (
<EmptyState
icon={<RiGroup2Fill />}
Expand Down Expand Up @@ -41,7 +41,7 @@ const StakeholdersPage = async () => {
</div>

<Card className="mx-auto mt-3 w-[28rem] sm:w-[38rem] md:w-full">
<StakeholderTable stakeholders={stakeholders.data} />
<StakeholderTable stakeholders={stakeholders} />
</Card>
</div>
);
Expand Down
46 changes: 29 additions & 17 deletions src/components/safe/existing/steps/general-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { useFormContext } from "react-hook-form";
import { NumericFormat } from "react-number-format";

export const GeneralDetailsFields = [
"safeId",
Expand Down Expand Up @@ -37,32 +38,43 @@ export const GeneralDetails = () => {
<FormField
control={form.control}
name="valuationCap"
render={({ field }) => (
<FormItem>
<FormLabel>Valuation cap</FormLabel>
<FormControl>
<Input
type={"text"}
{...field}
onChange={(e) => field.onChange(parseFloat(e.target.value))}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
)}
render={({ field }) => {
const { onChange, ...rest } = field;
return (
<FormItem>
<FormLabel>Valuation cap</FormLabel>
<FormControl>
<NumericFormat
thousandSeparator
allowedDecimalSeparators={["%"]}
decimalScale={2}
prefix={"$ "}
{...rest}
customInput={Input}
onValueChange={(values) => {
const { floatValue } = values;
onChange(floatValue);
}}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
);
}}
/>
<FormField
control={form.control}
name="discountRate"
render={({ field }) => (
<FormItem>
<FormLabel>Discount rate</FormLabel>
<FormLabel>Discount rate (optional)</FormLabel>
<FormControl>
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
<Input
type="text"
{...field}
onChange={(e) => field.onChange(parseFloat(e.target.value))}
onChange={(e) =>
field.onChange(Number.parseFloat(e.target.value))
}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
Expand All @@ -83,7 +95,7 @@ export const GeneralDetails = () => {
/>
</FormControl>
<FormLabel className="space-y-1 leading-none">
Pro-rata rights
Pro-rata rights (optional)
</FormLabel>
</FormItem>
)}
Expand Down
55 changes: 32 additions & 23 deletions src/components/safe/existing/steps/investor-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import {
SelectValue,
} from "@/components/ui/select";
import { api } from "@/trpc/react";
import { SelectSeparator } from "@radix-ui/react-select";
import * as SelectPrimitive from "@radix-ui/react-select";
import { SelectSeparator } from "@radix-ui/react-select";
import { RiAddCircleLine } from "@remixicon/react";
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import React, { useEffect, useMemo } from "react";
import { useEffect, useMemo } from "react";
import { useFormContext } from "react-hook-form";
import { NumericFormat } from "react-number-format";

export const ADD_STAKEHOLDER = "add-stakeholder";

Expand All @@ -42,16 +43,14 @@ export const InvestorDetails = () => {
const form = useFormContext();
const { data: session } = useSession();
const stakeholders = api.stakeholder.getStakeholders.useQuery();

const stakeholderId = form.watch("stakeholderId");

// eslint-disable-next-line react-hooks/exhaustive-deps
const currentStakeholder = useMemo(
() => stakeholders.data?.data?.find((sh) => sh.id === stakeholderId),
[stakeholderId],
() => stakeholders.data?.find((sh) => sh.id === stakeholderId),
[stakeholderId, stakeholders],
);

// eslint-disable-next-line react-hooks/exhaustive-deps
// biome-ignore lint/correctness/useExhaustiveDependencies: <explain>
useEffect(() => {
form.setValue("investorName", currentStakeholder?.name);
form.setValue("investorEmail", currentStakeholder?.email);
Expand All @@ -66,20 +65,31 @@ export const InvestorDetails = () => {
<FormField
control={form.control}
name="capital"
render={({ field }) => (
<FormItem>
<FormLabel>Capital</FormLabel>
<FormControl>
<Input
type="text"
{...field}
onChange={(e) => field.onChange(parseFloat(e.target.value))}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
)}
render={({ field }) => {
const { onChange, ...rest } = field;
return (
<FormItem>
<FormLabel>Valuation cap</FormLabel>
<FormControl>
<NumericFormat
thousandSeparator
allowedDecimalSeparators={["%"]}
decimalScale={2}
prefix={"$ "}
{...rest}
customInput={Input}
onValueChange={(values) => {
const { floatValue } = values;
onChange(floatValue);
}}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
);
}}
/>

<FormField
control={form.control}
name="issueDate"
Expand Down Expand Up @@ -123,11 +133,10 @@ export const InvestorDetails = () => {
}}
>
<SelectTrigger className="w-full">
<SelectValue placeholder="Select type" />
<SelectValue placeholder="Select stakeholder" />
</SelectTrigger>
<SelectContent>
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
{stakeholders?.data?.data?.map((sh) => (
{stakeholders?.data?.map((sh) => (
<SelectItem key={sh.id} value={sh.id}>
{sh.institutionName
? `${sh.institutionName} - ${sh.name}`
Expand Down
47 changes: 31 additions & 16 deletions src/components/safe/new/steps/general-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "@/components/ui/select";
import { SafeTemplateEnum } from "@/prisma/enums";
import { useFormContext } from "react-hook-form";
import { NumericFormat } from "react-number-format";

export const GeneralDetailsFields = [
"safeId",
Expand Down Expand Up @@ -71,35 +72,49 @@ export const GeneralDetails = () => {
</FormItem>
)}
/>

<FormField
control={form.control}
name="valuationCap"
render={({ field }) => (
<FormItem>
<FormLabel>Valuation cap</FormLabel>
<FormControl>
<Input
type={"text"}
{...field}
onChange={(e) => field.onChange(parseFloat(e.target.value))}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
)}
render={({ field }) => {
const { onChange, ...rest } = field;
return (
<FormItem>
<FormLabel>Valuation cap</FormLabel>
<FormControl>
<NumericFormat
thousandSeparator
allowedDecimalSeparators={["%"]}
decimalScale={2}
prefix={"$ "}
{...rest}
customInput={Input}
onValueChange={(values) => {
const { floatValue } = values;
onChange(floatValue);
}}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
);
}}
/>

<FormField
control={form.control}
name="discountRate"
render={({ field }) => (
<FormItem>
<FormLabel>Discount rate</FormLabel>
<FormLabel>Discount rate (optional)</FormLabel>
<FormControl>
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
<Input
type="text"
{...field}
onChange={(e) => field.onChange(parseFloat(e.target.value))}
onChange={(e) =>
field.onChange(Number.parseFloat(e.target.value))
}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
Expand All @@ -119,7 +134,7 @@ export const GeneralDetails = () => {
/>
</FormControl>
<FormLabel className="space-y-1 leading-none">
Pro-rata rights
Pro-rata rights (optional)
</FormLabel>
</FormItem>
)}
Expand Down
64 changes: 35 additions & 29 deletions src/components/safe/new/steps/investor-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import {
SelectValue,
} from "@/components/ui/select";
import { api } from "@/trpc/react";
import { SelectSeparator } from "@radix-ui/react-select";
import * as SelectPrimitive from "@radix-ui/react-select";
import { SelectSeparator } from "@radix-ui/react-select";
import { RiAddCircleLine } from "@remixicon/react";
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import React, { useEffect, useMemo } from "react";
import { useFormContext } from "react-hook-form";
import { NumericFormat } from "react-number-format";

export const ADD_STAKEHOLDER = "add-stakeholder";

Expand All @@ -43,43 +43,50 @@ export const InvestorDetails = () => {
const { data: session } = useSession();
const stakeholders = api.stakeholder.getStakeholders.useQuery();

const stakeholderId: string = form.watch("stakeholderId") as string;

// eslint-disable-next-line react-hooks/exhaustive-deps
const currentStakeholder = useMemo(
() => stakeholders.data?.data?.find((sh) => sh.id === stakeholderId),
[stakeholderId],
);
const setStakeholderData = (stakeholderId: string) => {
const currentStakeholder = stakeholders.data?.find(
(sh) => sh.id === stakeholderId,
);

// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => {
form.setValue("stakeholderId", stakeholderId);
form.setValue("investorName", currentStakeholder?.name);
form.setValue("investorEmail", currentStakeholder?.email);
form.setValue(
"investorInstitutionName",
currentStakeholder?.institutionName ?? "No institution",
);
}, [stakeholderId]);
};

return (
<div className="space-y-4">
<FormField
control={form.control}
name="capital"
render={({ field }) => (
<FormItem>
<FormLabel>Capital</FormLabel>
<FormControl>
<Input
type="text"
{...field}
onChange={(e) => field.onChange(parseFloat(e.target.value))}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
)}
render={({ field }) => {
const { onChange, ...rest } = field;
return (
<FormItem>
<FormLabel>Valuation cap</FormLabel>
<FormControl>
<NumericFormat
thousandSeparator
allowedDecimalSeparators={["%"]}
decimalScale={2}
prefix={"$ "}
{...rest}
customInput={Input}
onValueChange={(values) => {
const { floatValue } = values;
onChange(floatValue);
}}
/>
</FormControl>
<FormMessage className="text-xs font-light" />
</FormItem>
);
}}
/>

<FormField
control={form.control}
name="issueDate"
Expand Down Expand Up @@ -118,16 +125,15 @@ export const InvestorDetails = () => {
if (val === ADD_STAKEHOLDER) {
router.push(`/${session?.user.companyPublicId}/stakeholders`);
} else {
return form.setValue("stakeholderId", val);
setStakeholderData(val);
}
}}
>
<SelectTrigger className="w-full">
<SelectValue placeholder="Select type" />
<SelectValue placeholder="Select stakeholder" />
</SelectTrigger>
<SelectContent>
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
{stakeholders?.data?.data?.map((sh) => (
{stakeholders?.data?.map((sh) => (
<SelectItem key={sh.id} value={sh.id}>
{sh.institutionName
? `${sh.institutionName} - ${sh.name}`
Expand Down
Loading

0 comments on commit 2fec54a

Please sign in to comment.