Skip to content

Commit

Permalink
chore: added js doc
Browse files Browse the repository at this point in the history
  • Loading branch information
barttom committed Feb 13, 2024
1 parent 3384fc7 commit 4549e89
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/hooks/useReimbursementAccountStepFormSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ type UseReimbursementAccountStepFormSubmitParams = Pick<SubStepProps, 'isEditing
fieldIds: Array<keyof ReimbursementAccountDraftValues>;
};

/**
* Hook for handling submit method in ReimbursementAccount substeps.
* When user is in editing mode we should save values only when user confirm that
* @param formId - ID for particular form
* @param isEditing - if form is in editing mode
* @param onNext - callback
* @param fieldIds - field IDs for particular step
*/

export default function useReimbursementAccountStepFormSubmit({
formId = ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM,
isEditing,
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useSubStep/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type {SubStepProps, UseSubStep} from './types';

/**
* This hook ensures uniform handling of components across different screens, enabling seamless integration and navigation through sub steps of the VBBA flow.
* @param bodyContent - array of components to display in particular step
* @param onFinished - callback triggered after finish last step
* @param startFrom - initial index for bodyContent array
*/
export default function useSubStep<TProps extends SubStepProps>({bodyContent, onFinished, startFrom = 0}: UseSubStep<TProps>) {
const [screenIndex, setScreenIndex] = useState(startFrom);
Expand Down
7 changes: 6 additions & 1 deletion src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function isValidPastDate(date: string | Date): boolean {

/**
* Used to validate a value that is "required".
* @param value - field value
*/
function isRequiredFulfilled(value?: string | boolean | Date | unknown[] | Record<string, unknown> | null): boolean {
if (!value) {
Expand All @@ -91,11 +92,15 @@ function isRequiredFulfilled(value?: string | boolean | Date | unknown[] | Recor
}
return Boolean(value);
}

/**
* Used for getting errors for required fields.
*/
type GetFieldRequiredErrorsReturn<K extends string[]> = {[P in K[number]]: string};

/**
* Used to add requiredField error to the fields passed.
* @param values - all form values
* @param requiredFields - required fields for particular form
*/
function getFieldRequiredErrors<T extends OnyxFormValuesFields, K extends string[]>(values: T, requiredFields: K): GetFieldRequiredErrorsReturn<K> {
const errors: GetFieldRequiredErrorsReturn<K> = {} as GetFieldRequiredErrorsReturn<K>;
Expand Down
18 changes: 15 additions & 3 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ function getVBBADataForOnyx(currentStep?: BankAccountStep): OnyxData {
};
}

function addBusinessWebsiteForDraft(website: string) {
Onyx.merge(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT, {website});
function addBusinessWebsiteForDraft(websiteUrl: string) {
Onyx.merge(ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM_DRAFT, {website: websiteUrl});
}

/**
Expand Down Expand Up @@ -251,6 +251,8 @@ function deletePaymentBankAccount(bankAccountID: number) {
* Update the user's personal information on the bank account in database.
*
* This action is called by the requestor step in the Verified Bank Account flow
* @param bankAccountID - ID for bank account
* @param params - User personal data
*/
function updatePersonalInformationForBankAccount(bankAccountID: number, params: RequestorStepProps) {
API.write(
Expand Down Expand Up @@ -308,6 +310,13 @@ function clearReimbursementAccount() {
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, null);
}

/**
* Function to display and fetch data for Reimbursement Account step
* @param stepToOpen - current step to open
* @param subStep - particular step
* @param localCurrentStep - last step on device
* @param policyID - policy ID
*/
function openReimbursementAccountPage(stepToOpen: ReimbursementAccountStep, subStep: ReimbursementAccountSubStep, localCurrentStep: ReimbursementAccountStep, policyID: string) {
const onyxData: OnyxData = {
optimisticData: [
Expand Down Expand Up @@ -352,6 +361,7 @@ function openReimbursementAccountPage(stepToOpen: ReimbursementAccountStep, subS

/**
* Updates the bank account in the database with the company step data
* @param params - Business step form data
*/
function updateCompanyInformationForBankAccount(bankAccountID: number, params: CompanyStepProps) {
API.write(
Expand All @@ -367,6 +377,7 @@ function updateCompanyInformationForBankAccount(bankAccountID: number, params: C

/**
* Add beneficial owners for the bank account and verify the accuracy of the information provided
* @param params - Beneficial Owners step form params
*/
function updateBeneficialOwnersForBankAccount(bankAccountID: number, params: BeneficialOwnersStepProps) {
API.write(
Expand All @@ -382,6 +393,7 @@ function updateBeneficialOwnersForBankAccount(bankAccountID: number, params: Ben

/**
* Accept the ACH terms and conditions and verify the accuracy of the information provided
* @param params - Verification step form params
*/
function acceptACHContractForBankAccount(bankAccountID: number, params: ACHContractStepProps) {
API.write(
Expand All @@ -397,7 +409,7 @@ function acceptACHContractForBankAccount(bankAccountID: number, params: ACHContr

/**
* Create the bank account with manually entered data.
*
* @param plaidMask - scheme for Plaid account number
*/
function connectBankAccountManually(bankAccountID: number, accountNumber?: string, routingNumber?: string, plaidMask?: string, policyID?: string) {
const parameters: ConnectBankAccountManuallyParams = {
Expand Down

0 comments on commit 4549e89

Please sign in to comment.