-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SlackMessage): udpated slack message cleaner, concise with stron…
…ger typescript
- Loading branch information
1 parent
74afe70
commit c29eabd
Showing
5 changed files
with
144 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import type { CreditApplicant } from 'typings' | ||
|
||
export type SlackBlocks = Array<ReturnType<typeof createSlackSection> | { type: 'divider' }> | ||
|
||
export function createSlackSection(text: string) { | ||
return { | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text, | ||
}, | ||
} | ||
} | ||
|
||
export function formatSlackApplicant(applicant: CreditApplicant, role: 'Primary' | 'Joint') { | ||
const blocks: SlackBlocks = [] | ||
blocks.push({ type: 'divider' }) | ||
blocks.push( | ||
createSlackSection( | ||
`*${role} Applicant:*\n*Full name:* ${applicant.firstName} ${applicant.middleName || ''} ${ | ||
applicant.lastName | ||
}\n*Phone:* ${applicant.phone} ${applicant.phoneType}\n*Email:* ${ | ||
applicant.email | ||
}\n*Date of Birth:* ${applicant.dateOfBirth}\n*SSN:* ${applicant.ssn}` | ||
) | ||
) | ||
blocks.push( | ||
createSlackSection( | ||
`*Residence*\n*Address:* ${applicant.addressLine1}\n*City:* ${applicant.city}\n*State:* ${ | ||
applicant.state | ||
}\n*Zip Code:* ${applicant.zipCode}\n*Time at address:* ${applicant.addressYears} yrs ${ | ||
applicant.addressMonths ? applicant.addressMonths + 'mo' : '' | ||
}\n*Monthly payment/rent:* ${applicant.rentMortgagePaymentAmount}` | ||
) | ||
) | ||
if (Number(applicant.addressYears) < 2) { | ||
blocks.push( | ||
createSlackSection( | ||
`*Previous Residence*\n*Address:* ${applicant.prevAddressLine1}\n*City:* ${ | ||
applicant.prevCity | ||
}\n*State:* ${applicant.prevState}\n*Zip Code:* ${ | ||
applicant.prevZipCode | ||
}\n*Time at address:* ${applicant.prevAddressYears} yrs ${ | ||
applicant.prevAddressMonths ? applicant.prevAddressMonths + 'mo' : '' | ||
}\n*Monthly payment/rent:* ${applicant.prevRentMortgagePaymentAmount}` | ||
) | ||
) | ||
} | ||
blocks.push( | ||
createSlackSection( | ||
`*Drivers License*\n*License number:* ${applicant.licenseNumber}\n*State:* ${applicant.licenseState}` | ||
) | ||
) | ||
blocks.push( | ||
createSlackSection( | ||
`*Employment History*\n*Employer name:* ${applicant.employerName}\n*Employment Status:* ${ | ||
applicant.employmentStatusCode | ||
}\n*Employer phone:* ${applicant.employerPhone}\n*Occupation:* ${ | ||
applicant.employmentTitle | ||
}\n*Time on job:* ${applicant.timeOnJobYears} yrs ${ | ||
applicant.timeOnJobMonths ? applicant.timeOnJobMonths + 'mo' : '' | ||
}\n*Monthly income:* ${applicant.incomeAmount}` | ||
) | ||
) | ||
if (Number(applicant.timeOnJobYears) < 2) { | ||
blocks.push( | ||
createSlackSection( | ||
`*Previous Employment*\n*Employer name:* ${ | ||
applicant.previousEmployerName | ||
}\n*Employer phone:* ${applicant.prevEmployerPhone}\n*Occupation:* ${ | ||
applicant.prevEmploymentTitle | ||
}\n*Time on job:* ${applicant.prevTimeOnJobYears} yrs ${ | ||
applicant.prevTimeOnJobMonths ? applicant.prevTimeOnJobMonths + 'mo' : '' | ||
}\n*Monthly income:* ${applicant.prevIncomeAmount}` | ||
) | ||
) | ||
} | ||
blocks.push( | ||
createSlackSection( | ||
`*Other Income*\n*Description:* ${applicant.otherIncomeSourceDescription}\n*Monthly Amount:* ${applicant.otherIncomeAmount}` | ||
) | ||
) | ||
return blocks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use server' | ||
|
||
import formatDate from '@/utils/formatDate' | ||
import type { CreditApplicant, VehicleOfInterest } from 'typings' | ||
import { createSlackSection, formatSlackApplicant, type SlackBlocks } from './slack.helpers' | ||
|
||
interface SlackParams { | ||
url: string | undefined | ||
data: { | ||
primary: CreditApplicant | ||
secondary: CreditApplicant | ||
vehicle: VehicleOfInterest | ||
tradeIn: { | ||
id: string | ||
lienholder: string | ||
allowance: number | ||
} | ||
} | ||
} | ||
|
||
export async function slackMessageCredit({ url, data }: SlackParams) { | ||
const date = formatDate(new Date(), true) | ||
const blocks: SlackBlocks = [] | ||
|
||
blocks.push( | ||
createSlackSection( | ||
`*${data.primary.firstName} ${data.primary.lastName}* | ${date} :moneybag:\n* ${data.primary.email} | ${date}*` | ||
) | ||
) | ||
blocks.push(...formatSlackApplicant(data.primary, 'Primary')) | ||
|
||
if (data.secondary) { | ||
blocks.push(...formatSlackApplicant(data.secondary, 'Joint')) | ||
} | ||
|
||
blocks.push({ type: 'divider' }) | ||
blocks.push( | ||
createSlackSection( | ||
`*Vehicle of Interest*\n*Cash Down:* ${data?.vehicle?.cashDown}\n*VIN:* ${data.vehicle.vin}\n*Year:* ${data.vehicle.year}\n*Make:* ${data.vehicle.make}\n*Model:* ${data.vehicle.model}\n*Odometer:* ${data.vehicle.mileage}\n*Price:* ${data.vehicle.price}` | ||
) | ||
) | ||
|
||
if (data.tradeIn) { | ||
blocks.push({ type: 'divider' }) | ||
blocks.push( | ||
createSlackSection( | ||
`*Trade Information*\n*Record Id:* ${data.tradeIn.id}\n*Lender:* ${data.tradeIn.lienholder}\n*Trade In Allowance:* ${data.tradeIn.allowance}` | ||
) | ||
) | ||
} | ||
|
||
await fetch(url!, { | ||
method: 'POST', | ||
body: JSON.stringify({ blocks }), | ||
headers: { 'Content-Type': 'application/json' }, | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.