import classnames from 'classnames'; import { action } from 'mobx'; import { FC, useCallback } from 'react'; import { observer, useLocalStore } from 'mobx-react'; import { BodyText, Button, Card, Container, Form, Grid, Layout, Link, Stack, Text, Tooltip, } from '@servicetitan/design-system'; import { DateRangeColumnMenuFilter, multiSelectColumnMenuFilter, StandardColumnMenuFilter, Table, TableColumn, TableState, TableCellProps, } from '@servicetitan/table'; import { ResultDefinitionsModal } from '../result-definitions-modal'; interface EmailValidationLocalStore { open: boolean; setOpen(state: boolean): void; } export interface EmailValidationTableRecord { id: number; active: boolean; createdOn: Date; email?: string | undefined; result: T; dateAdded?: Date | undefined; } export interface EmailValidationProps< TEmailValidationType extends string | number = string, TEmailValidationResult extends string | number = string, > { className?: string; loading: boolean; resultGrid: TableState>; validationRiskType?: TEmailValidationType; handleDownload(): void; setValidationRiskType(type: TEmailValidationType): void; } interface EmailValidationHocOptions< TEmailValidationType extends string | number = string, TEmailValidationResult extends string | number = string, > { resultToText: Map; levelTypeMap: { high: TEmailValidationType; medium: TEmailValidationType; low: TEmailValidationType; }; levelResultMap: Map; resultToTooltipText: Map; TenantDateCell: FC; } export function emailValidationHoc< TEmailValidationType extends string | number = string, TEmailValidationResult extends string | number = string, >({ resultToText, levelTypeMap, resultToTooltipText, levelResultMap, TenantDateCell, }: EmailValidationHocOptions) { const ResultColumnMenuFilter = multiSelectColumnMenuFilter( [...resultToText.keys()], result => resultToText.get(result)!, ); const ResultCell: FC = props => { const { result } = props.dataItem as { result: TEmailValidationResult }; return ( {resultToText.get(result)} ); }; function EmailValidationImpl({ className, handleDownload, loading, resultGrid, setValidationRiskType, validationRiskType, }: EmailValidationProps) { const localStore: EmailValidationLocalStore = useLocalStore(() => ({ open: false, setOpen: action(function (this: EmailValidationLocalStore, state: boolean) { this.open = state; }), })); const handleCheck = useCallback( (riskType: TEmailValidationType) => () => { setValidationRiskType(riskType); }, [setValidationRiskType], ); const handleClickLearnMore = () => { localStore.setOpen(true); }; const handleClose = () => { localStore.setOpen(false); }; const getResultsItemsForLevel = (level: TEmailValidationType) => { return levelResultMap .get(level) ?.map(r => resultToText.get(r)) .map(r =>
{r}
); }; return ( Email Validation Email Validation acts like a filter that will block emails from going to bad email addresses. You won't necessarily see these emails in your suppression list, but it will effect your number “Sent”. Set Your Preference Choose what level you want to enable for auto-suppression. Learn More High (recommended) {getResultsItemsForLevel(levelTypeMap.high)} } checked={validationRiskType === levelTypeMap.high} onChange={handleCheck(levelTypeMap.high)} className="qa-email-validation-high" /> Medium {getResultsItemsForLevel(levelTypeMap.medium)} } checked={validationRiskType === levelTypeMap.medium} onChange={handleCheck(levelTypeMap.medium)} className="qa-email-validation-medium" /> Low {getResultsItemsForLevel(levelTypeMap.low)} } checked={validationRiskType === levelTypeMap.low} onChange={handleCheck(levelTypeMap.low)} className="qa-email-validation-low" />
{localStore.open && }
); } return observer(EmailValidationImpl); }