Skip to content

Commit

Permalink
correct types
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-justin committed Sep 23, 2024
1 parent 610b03b commit 4b40ed3
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 162 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@better-giving/assets": "1.0.18",
"@better-giving/registration": "1.0.8",
"@better-giving/registration": "1.0.11",
"@gsap/react": "2.1.1",
"@headlessui/react": "2.1.0",
"@hookform/error-message": "2.0.1",
Expand Down
19 changes: 8 additions & 11 deletions src/pages/Applications/Filter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { QueryParams } from "@better-giving/registration/approval";
import { Popover, PopoverButton } from "@headlessui/react";
import { yupResolver } from "@hookform/resolvers/yup";
import Icon, { DrawerIcon } from "components/Icon";
Expand All @@ -6,14 +7,13 @@ import { cleanObject } from "helpers/cleanObject";
import { weeksAgo } from "helpers/weeksAgo";
import { type FormEventHandler, useRef } from "react";
import { FormProvider, useForm } from "react-hook-form";
import type { ApplicationsQueryParams } from "types/aws";
import Form from "./Form";
import { schema } from "./schema";
import type { FormValues as FV } from "./types";

type Props = {
classes?: string;
setParams: React.Dispatch<React.SetStateAction<ApplicationsQueryParams>>;
setParams: React.Dispatch<React.SetStateAction<QueryParams>>;
isDisabled: boolean;
};

Expand All @@ -29,7 +29,7 @@ export default function Filter({ setParams, classes = "", isDisabled }: Props) {
startDate: dateToFormFormat(weeksAgo("now", 1)),
endDate: dateToFormFormat(new Date()),
hqCountry: { name: "", flag: "", code: "" },
status: { label: "Under Review", value: "Under Review" },
status: { label: "Under Review", value: "02" },
},
});

Expand All @@ -48,21 +48,18 @@ export default function Filter({ setParams, classes = "", isDisabled }: Props) {
async function submit(data: FV) {
setParams(
cleanObject({
regDateStart: ISOdate(data.startDate),
regDateEnd: ISOdate(data.endDate, true),
regStatus: data.status.value,
hqCountry: data.hqCountry.name,
startDate: ISOdate(data.startDate),
endDate: ISOdate(data.endDate, true),
status: data.status.value,
country: data.hqCountry.name,
})
);
buttonRef.current?.click();
}

const onReset: FormEventHandler<HTMLFormElement> = () => {
reset();
setParams({
limit: 10,
regStatus: "Under Review",
});
setParams({ status: "02" });
buttonRef.current?.click();
};
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { EndowClaim } from "@better-giving/registration/models";
import { appRoutes, regRoutes } from "constants/routes";
import { isEmpty } from "helpers";
import type { PropsWithChildren } from "react";
import { Link } from "react-router-dom";
import type { EndowClaim } from "types/aws";
import { useProfileContext } from "../../../ProfileContext";
import DonateButton from "../../DonateButton";
import Socials from "./Socials";
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Registration/Steps/ContactDetails/Form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ReferralMethod, Role } from "@better-giving/registration/models";
import LoadText from "components/LoadText";
import { Selector } from "components/Selector";
import { Field, Label } from "components/form";
import { APP_NAME } from "constants/env";
import type { ContactRoles, ReferralMethods } from "types/aws";
import { referralOptions, roleOptions } from "../constants";
import type { FormValues as FV } from "../types";
import useSubmit from "./useSubmit";
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function Form({ classes = "" }: { classes?: string }) {
<Label required className="mb-2">
What's your role within the organization?
</Label>
<Selector<FV, "org_role", ContactRoles>
<Selector<FV, "org_role", Role>
name="org_role"
options={roleOptions}
classes={{ options: "text-sm" }}
Expand All @@ -81,7 +81,7 @@ export default function Form({ classes = "" }: { classes?: string }) {
<Label required className="mb-2">
How did you find about us?
</Label>
<Selector<FV, "referral_method", ReferralMethods>
<Selector<FV, "referral_method", ReferralMethod>
name="referral_method"
options={referralOptions}
classes={{ options: "text-sm" }}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Registration/Steps/ContactDetails/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ContactRoles, ReferralMethods } from "types/aws";
import type { ReferralMethod, Role } from "@better-giving/registration/models";
import type { OptionType } from "types/components";

export const roles: { [key in ContactRoles]: string } = {
export const roles: { [key in Role]: string } = {
"": "",
president: "Chairperson / President",
"vice-president": "Vice-chairperson / Vice president",
Expand All @@ -16,7 +16,7 @@ export const roles: { [key in ContactRoles]: string } = {
communications: "Communications",
other: "Other",
};
export const referralMethods: { [key in ReferralMethods]: string } = {
export const referralMethods: { [key in ReferralMethod]: string } = {
"": "",
"better-giving-alliance": "Better Giving Alliance",
discord: "Discord",
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Registration/Steps/ContactDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ReferralMethod, Role } from "@better-giving/registration/models";
import { yupResolver } from "@hookform/resolvers/yup";
import { useAuthenticatedUser } from "contexts/Auth";
import { FormProvider, useForm } from "react-hook-form";
import type { ContactRoles, ReferralMethods } from "types/aws";
import type { OptionType } from "types/components";
import { useRegState, withStepGuard } from "../StepGuard";
import Form from "./Form";
Expand Down Expand Up @@ -54,10 +54,10 @@ function ContactDetails() {

export default withStepGuard(ContactDetails);

function toRoleOption(value: ContactRoles): OptionType<ContactRoles> {
function toRoleOption(value: Role): OptionType<Role> {
return { value, label: roles[value] };
}

function toReferralOption(value: ReferralMethods): OptionType<ReferralMethods> {
function toReferralOption(value: ReferralMethod): OptionType<ReferralMethod> {
return { value, label: referralMethods[value] };
}
8 changes: 4 additions & 4 deletions src/pages/Registration/Steps/ContactDetails/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ReferralMethod, Role } from "@better-giving/registration/models";
import { optionType } from "schemas/shape";
import { requiredString } from "schemas/string";
import type { SchemaShape } from "schemas/types";
import type { ContactRoles, ReferralMethods } from "types/aws";
import type { OptionType } from "types/components";
import { type ObjectSchema, object, string } from "yup";
import type { FormValues } from "./types";
Expand All @@ -13,16 +13,16 @@ const referralMethodKey: Key = "referral_method";
const otherRole = string()
.trim()
.when(roleKey, ([option], schema) =>
(option as OptionType<ContactRoles>).value === "other"
(option as OptionType<Role>).value === "other"
? schema.required("required")
: schema
);

const otherReferralMethod = (referralMethod: ReferralMethods) =>
const otherReferralMethod = (referralMethod: ReferralMethod) =>
string()
.trim()
.when(referralMethodKey, ([option], schema) =>
(option as OptionType<ReferralMethods>).value === referralMethod
(option as OptionType<ReferralMethod>).value === referralMethod
? schema.required("required")
: schema
);
Expand Down
13 changes: 9 additions & 4 deletions src/pages/Registration/Steps/ContactDetails/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import type {
Contact,
Init,
ReferralMethod,
Role,
} from "@better-giving/registration/models";
import type { OverrideProperties } from "type-fest";
import type { ContactRoles, ReferralMethods, RegV2 } from "types/aws";
import type { OptionType } from "types/components";

export type FormValues = OverrideProperties<
RegV2.Contact & Pick<RegV2.Init, "registrant_id" | "id">,
Contact & Pick<Init, "registrant_id" | "id">,
{
org_role: OptionType<ContactRoles>;
referral_method: OptionType<ReferralMethods>;
org_role: OptionType<Role>;
referral_method: OptionType<ReferralMethod>;
}
>;
118 changes: 59 additions & 59 deletions src/pages/Registration/Steps/Dashboard/EndowmentStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import type { Submission } from "@better-giving/registration/models";
import { isRejected } from "@reduxjs/toolkit";
import Icon from "components/Icon";
import LoadText from "components/LoadText";
import { steps } from "pages/Registration/routes";
import type { MouseEventHandler } from "react";
import { Link } from "react-router-dom";
import type { RegV2 } from "types/aws";
import { useRegState } from "../StepGuard";

type Props = {
isSubmitting: boolean;
status: Exclude<RegV2.Submission, object>;
status?: Exclude<Submission, { endowment_id: any }>;
onSubmit: MouseEventHandler<HTMLButtonElement>;
classes?: string;
};
Expand All @@ -21,67 +22,66 @@ export default function EndowmentStatus({
}: Props) {
const { data } = useRegState<3>();

switch (status) {
case "rejected":
return (
<div className={`max-sm:grid text-red dark:text-red-l3 ${classes}`}>
<p className="mb-6 max-sm:grid justify-items-center gap-2">
<Icon
type="Info"
className="inline relative bottom-px mr-2"
size={20}
/>
<span className="max-sm:text-center">
Your nonprofit's application has been rejected.
</span>
</p>
<button
type="button"
onClick={onSubmit}
disabled={isSubmitting}
className="min-w-[8rem] btn-blue btn-reg"
>
<LoadText isLoading={isSubmitting}>Resubmit</LoadText>
</button>
</div>
);

case "in-review":
return (
<div
className={`max-sm:grid justify-items-center gap-2 text-navy-l1 dark:text-navy-l2 ${classes}`}
>
if (isRejected(status)) {
return (
<div className={`max-sm:grid text-red dark:text-red-l3 ${classes}`}>
<p className="mb-6 max-sm:grid justify-items-center gap-2">
<Icon
type="HourglassSplit"
className="relative bottom-px inline mr-2"
size={18}
type="Info"
className="inline relative bottom-px mr-2"
size={20}
/>
<span className="max-sm:text-center">
Your application has been submitted for review
Your nonprofit's application has been rejected.
</span>
</div>
);
</p>
<button
type="button"
onClick={onSubmit}
disabled={isSubmitting}
className="min-w-[8rem] btn-blue btn-reg"
>
<LoadText isLoading={isSubmitting}>Resubmit</LoadText>
</button>
</div>
);
}

default:
return (
<div className={`grid grid-cols-2 sm:flex gap-2 ${classes}`}>
<Link
aria-disabled={isSubmitting}
to={`../${steps.banking}`}
state={data.init}
className="py-3 min-w-[8rem] btn-outline-filled btn-reg"
>
Back
</Link>
<button
type="button"
disabled={isSubmitting}
onClick={onSubmit}
className="py-3 min-w-[8rem] btn-blue btn-reg"
>
<LoadText isLoading={isSubmitting}>Continue</LoadText>
</button>
</div>
);
if (status === "in-review") {
return (
<div
className={`max-sm:grid justify-items-center gap-2 text-navy-l1 dark:text-navy-l2 ${classes}`}
>
<Icon
type="HourglassSplit"
className="relative bottom-px inline mr-2"
size={18}
/>
<span className="max-sm:text-center">
Your application has been submitted for review
</span>
</div>
);
}

return (
<div className={`grid grid-cols-2 sm:flex gap-2 ${classes}`}>
<Link
aria-disabled={isSubmitting}
to={`../${steps.banking}`}
state={data.init}
className="py-3 min-w-[8rem] btn-outline-filled btn-reg"
>
Back
</Link>
<button
type="button"
disabled={isSubmitting}
onClick={onSubmit}
className="py-3 min-w-[8rem] btn-blue btn-reg"
>
<LoadText isLoading={isSubmitting}>Continue</LoadText>
</button>
</div>
);
}
10 changes: 7 additions & 3 deletions src/pages/Registration/Steps/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Prompt from "components/Prompt";
import { regRoutes } from "constants/routes";
import { useErrorContext } from "contexts/ErrorContext";
import { useModalContext } from "contexts/ModalContext";
import type { CompleteReg } from "pages/Registration/types";
import { Navigate } from "react-router-dom";
import { useSubmitMutation } from "services/aws/registration";
import type { Step6Data } from "../../types";
import { useRegState, withStepGuard } from "../StepGuard";
import EndowmentStatus from "./EndowmentStatus";
import Step from "./Step";
Expand All @@ -16,7 +16,7 @@ function Dashboard() {
const { showModal } = useModalContext();
const { handleError } = useErrorContext();

const submit = async ({ init }: CompleteReg) => {
const submit = async ({ init }: Step6Data) => {
try {
await submitApplication(init.id).unwrap();
if (window.hasOwnProperty("lintrk")) {
Expand All @@ -40,7 +40,11 @@ function Dashboard() {
const { submission } = data;
const isStepDisabled = isSubmitting || submission === "in-review";

if (typeof submission === "object") {
if (
submission &&
typeof submission !== "string" &&
"endowment_id" in submission
) {
return <Navigate to={`../../${regRoutes.success}`} state={data} />;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isIrs501c3 } from "types/aws";
import { isIrs501c3 } from "@better-giving/registration/models";
import { useRegState, withStepGuard } from "../StepGuard";
import FSADocumentation from "./FSA";
import NonFSA from "./NonFSA";
Expand Down
5 changes: 3 additions & 2 deletions src/pages/Registration/Steps/Documentation/FSA/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FsaDocs } from "@better-giving/registration/models";
import { yupResolver } from "@hookform/resolvers/yup";
import { FormProvider, useForm } from "react-hook-form";
import type { FileObject, RegV2 } from "types/aws";
import type { FileObject } from "types/aws";
import type { FileDropzoneAsset } from "types/components";
import Form from "./Form";
import { schema } from "./schema";
Expand Down Expand Up @@ -28,7 +29,7 @@ export default function FSADocumentation(props: Props) {
);
}

function formFormat(doc: RegV2.FsaDocs): FormValues {
function formFormat(doc: FsaDocs): FormValues {
return {
//level 1
outdated: doc.outdated,
Expand Down
Loading

0 comments on commit 4b40ed3

Please sign in to comment.