Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | import { Text } from "@common/Text";
import { Box, Divider, Stack, styled } from "@mui/material";
import { palette } from "@palette";
import { useCustomTheme } from "@theme/hooks/useCustomTheme";
type Section = {
label: string;
fields: string[];
};
const config = [
{
label: "Accounts",
fields: [
"Account ID",
"Mask",
"Name",
"Official Name",
"Persistent Account ID",
"Subtype",
"Type",
"Balances",
],
},
{
label: "Item",
fields: [
"Consent Expiration Time",
"Error",
"Institution ID",
"Item ID",
"Update Type",
"Webhook",
"Available Products",
"Billed Products",
"Consented Products",
"Products",
],
},
{
label: "Numbers",
fields: ["ACH", "Bacs", "Eft", "International"],
},
] as Section[];
const PlaidAccountInfo = ({ data }: { data: any }) => {
const { isMobileView } = useCustomTheme();
return (
<Stack
spacing="16px"
padding={isMobileView ? "4px" : "24px"}
overflow="auto"
>
{config.map((section, sectionInd) => {
const sectionName = section.label.toLowerCase();
const sectionData = data[sectionName];
const isSectionArray = Array.isArray(sectionData);
const sectionDataArr =
isSectionArray && sectionData.length ? sectionData : [sectionData];
return sectionDataArr.map((sectionDataItem, sectionItemInd) => (
<Stack key={sectionInd}>
{!sectionItemInd && (
<Text
color={palette.neutral[70]}
fontSize={18}
padding="8px 16px"
>
{section.label}
</Text>
)}
{section.fields.map((field, fInd) => (
<Row key={fInd} isEven={fInd % 2 === 0}>
<Text color={palette.neutral[70]}>{field}</Text>
<Stack>
{getSectionFieldData(sectionDataItem, field).map((val, i) => (
<Text
key={i}
color={palette.neutral[80]}
sx={{
wordBreak: "break-all",
textTransform: "capitalize",
}}
>
{val}
</Text>
))}
</Stack>
</Row>
))}
{sectionInd !== config.length - 1 && (
<Divider color={palette.neutral[20]} sx={{ marginTop: "16px" }} />
)}
</Stack>
));
})}
</Stack>
);
};
export default PlaidAccountInfo;
const Row = styled(Box, {
shouldForwardProp: (prop) => prop !== "isEven",
})<{ isEven: boolean }>(({ theme, isEven }) => ({
display: "grid",
gridTemplateColumns: "1fr 1fr",
padding: "4px 16px",
borderRadius: "4px",
backgroundColor: isEven ? theme?.palette.neutral.white : "transparent",
}));
const getStringArrayFromObject = (obj: { [key: string]: string }) =>
Object.entries(obj).map(
([key, value]) => `${key}: ${value ? value : "None"}`,
);
const getFieldData = (fieldVal: any): string[] => {
if (typeof fieldVal === "string") return [fieldVal];
if (Array.isArray(fieldVal) && fieldVal.length) {
if (typeof fieldVal[0] === "object" && fieldVal[0] !== null) {
return fieldVal.flatMap((item) => getStringArrayFromObject(item));
} else {
return fieldVal;
}
}
if (!fieldVal || (Array.isArray(fieldVal) && !fieldVal.length)) {
return ["None"];
}
if (typeof fieldVal === "object") {
return getStringArrayFromObject(fieldVal);
}
return ["None"];
};
const getSectionFieldData = (sectionDataItem: any, field: string): string[] => {
const fieldName = field.toLowerCase().replaceAll(" ", "_");
const fieldVal = sectionDataItem ? sectionDataItem[fieldName] : null;
return getFieldData(fieldVal).map((s) => s.replaceAll("_", " "));
};
|