Skip to content

Commit

Permalink
registration state
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-justin committed Sep 21, 2024
1 parent a8c77c5 commit fdee2f1
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 212 deletions.
189 changes: 14 additions & 175 deletions src/pages/Registration/Steps/getRegistrationState.ts
Original file line number Diff line number Diff line change
@@ -1,194 +1,33 @@
import {
type BankingDetails,
type DoneBanking,
type DoneDocs,
type DoneFSAInquiry,
type DoneOrgDetails,
type EndowClaim,
type FSAInquiry,
type InitContact,
type OrgDetails,
type SavedRegistration,
type TDocumentation,
isDoneBanking,
isDoneContact,
isDoneDocs,
isDoneFSAInquiry,
isDoneOrgDetails,
isSubmitted,
} from "types/aws";
import { type RegV2, isDone } from "types/aws";
import { steps } from "../routes";
import type { InitReg, RegistrationState } from "../types";
import type { RegistrationState } from "../types";

export function getRegistrationState(reg: SavedRegistration): {
export function getRegistrationState(reg: RegV2.Record): {
state: RegistrationState;
nextStep: steps;
} {
if (isSubmitted(reg)) {
const { ContactPerson: c, Registration: r } = reg;
return {
state: {
step: 6,
data: {
init: initReg(c, r.InitClaim),
contact: { ...c, orgName: r.OrganizationName },
orgDetails: orgDetails(r),
fsaInquiry: fsaInquiry(r),
documentation: docs(r),
banking: bankDetails(r),
status: r.RegistrationStatus,
endowId: r.EndowmentId,
},
},
nextStep: steps.summary,
};
if (isDone.step6(reg)) {
return { state: { step: 6, data: reg }, nextStep: steps.summary };
}

if (isDoneBanking(reg)) {
const { ContactPerson: c, Registration: r } = reg;
return {
state: {
step: 5,
data: {
init: initReg(c, r.InitClaim),
contact: { ...c, orgName: r.OrganizationName },
orgDetails: orgDetails(r),
fsaInquiry: fsaInquiry(r),
documentation: docs(r),
banking: bankDetails(r),
},
},
nextStep: steps.summary,
};
if (isDone.step5(reg)) {
return { state: { step: 5, data: reg }, nextStep: steps.summary };
}

if (isDoneDocs(reg)) {
const { ContactPerson: c, Registration: r } = reg;
const isSignedFSA =
r.Documentation.DocType === "FSA"
? !!r.Documentation.SignedFiscalSponsorshipAgreement
: true;

return {
state: {
//cast to 4 (type only) to conform to type `RegStep4` which accepts documentation
step: (isSignedFSA ? 4 : 3) as 4,
data: {
init: initReg(c, r.InitClaim),
contact: { ...c, orgName: r.OrganizationName },
orgDetails: orgDetails(r),
fsaInquiry: fsaInquiry(r),
//even step is has value of `3` user could still go to step 4 with documentation pre-filled from previous uploads
documentation: docs(r),
},
},
nextStep: steps.banking,
};
if (isDone.step4(reg)) {
return { state: { step: 4, data: reg }, nextStep: steps.banking };
}

if (isDoneFSAInquiry(reg)) {
const { ContactPerson: c, Registration: r } = reg;
return {
state: {
step: 3,
data: {
init: initReg(c, r.InitClaim),
contact: { ...c, orgName: r.OrganizationName },
orgDetails: orgDetails(r),
fsaInquiry: fsaInquiry(r),
},
},
nextStep: steps.docs,
};
}
if (isDoneOrgDetails(reg)) {
const { ContactPerson: c, Registration: r } = reg;
return {
state: {
step: 2,
data: {
init: initReg(c, r.InitClaim),
contact: { ...c, orgName: r.OrganizationName },
orgDetails: orgDetails(r),
},
},
nextStep: steps.fsaInquiry,
};
if (isDone.step3(reg)) {
return { state: { step: 3, data: reg }, nextStep: steps.docs };
}

if (isDoneContact(reg)) {
const { ContactPerson: c, Registration: r } = reg;
return {
state: {
step: 1,
data: {
init: initReg(c, r.InitClaim),
contact: { ...c, orgName: r.OrganizationName },
},
},
nextStep: steps.orgDetails,
};
if (isDone.step2(reg)) {
return { state: { step: 2, data: reg }, nextStep: steps.fsaInquiry };
}

const { ContactPerson: c, Registration: r } = reg;
return {
state: {
step: 1,
data: {
init: initReg(c, r.InitClaim),
},
},
state: { step: 1, data: reg satisfies RegV2.Step1 },
nextStep: steps.contact,
};
}

function initReg(i: InitContact, claim?: EndowClaim): InitReg {
return {
email: i.Email,
reference: i.PK,
claim,
};
}

function orgDetails(reg: DoneOrgDetails["Registration"]): OrgDetails {
return {
Website: reg.Website,
HqCountry: reg.HqCountry,
ActiveInCountries: reg.ActiveInCountries,
EndowDesignation: reg.EndowDesignation,
KycDonorsOnly: reg.KycDonorsOnly,
UN_SDG: reg.UN_SDG,
};
}

function docs(reg: DoneDocs["Registration"]): TDocumentation["Documentation"] {
const doc = reg.Documentation;
if (doc.DocType === "Non-FSA") {
return { EIN: doc.EIN, DocType: doc.DocType, Claim: doc.Claim };
}
return {
DocType: doc.DocType,
ProofOfIdentity: doc.ProofOfIdentity,
RegistrationNumber: doc.RegistrationNumber,
ProofOfRegistration: doc.ProofOfRegistration,
LegalEntityType: doc.LegalEntityType,
ProjectDescription: doc.ProjectDescription,
FiscalSponsorshipAgreementSigningURL:
doc.FiscalSponsorshipAgreementSigningURL,
SignedFiscalSponsorshipAgreement: doc.SignedFiscalSponsorshipAgreement,
};
}

function bankDetails(reg: DoneBanking["Registration"]): BankingDetails {
return {
BankStatementFile: reg.BankStatementFile,
wise_recipient_id: reg.wise_recipient_id,
};
}

function fsaInquiry(reg: DoneFSAInquiry["Registration"]): FSAInquiry {
return {
AuthorizedToReceiveTaxDeductibleDonations:
reg.AuthorizedToReceiveTaxDeductibleDonations,
};
}
14 changes: 7 additions & 7 deletions src/pages/Registration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
EndowClaim,
FSAInquiry,
OrgDetails,
RegistrationStatus,
RegV2,
TDocumentation,
} from "types/aws";

Expand Down Expand Up @@ -47,36 +47,36 @@ type Step5Data = Data<
/** contact details */
type RegStep1 = {
step: 1;
data: Step1Data;
data: RegV2.Step1;
};

/** org details */
type RegStep2 = {
step: 2;
data: Step2Data;
data: RegV2.Step2;
};

/** fsa inquiry */
type RegStep3 = {
step: 3;
data: Step3Data;
data: RegV2.Step3;
};

/** documentation */
export type RegStep4 = {
step: 4;
data: Step4Data;
data: RegV2.Step4;
};

/** banking */
type RegStep5 = {
step: 5;
data: Step5Data;
data: RegV2.Step5;
};

type RegStep6 = {
step: 6;
data: CompleteRegistration & { status: RegistrationStatus };
data: RegV2.Step6;
};

export type RegistrationState =
Expand Down
Loading

0 comments on commit fdee2f1

Please sign in to comment.