Files
hexabot/frontend/src/components/visual-editor/form/inputs/ReplacementTokens.tsx
Mohamed Marrouchi 30e5766487 feat: initial commit
2024-09-10 10:50:11 +01:00

116 lines
3.9 KiB
TypeScript

/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import {
Accordion,
AccordionDetails,
AccordionSummary,
List,
ListItem,
ListItemText,
Typography,
} from "@mui/material";
import { useTranslation } from "react-i18next";
import { useFind } from "@/hooks/crud/useFind";
import { EntityType } from "@/services/types";
function ReplacementTokens() {
const { t } = useTranslation();
const userInfos = [
{ name: "first_name", label: t("label.user_first_name") },
{ name: "last_name", label: t("label.user_last_name") },
];
const userLocation = [
{ name: "lat", label: t("label.user_location_lat") },
{ name: "lon", label: t("label.user_location_lon") },
{ name: "address.country", label: t("label.user_location_country") },
{ name: "address.state", label: t("label.user_location_state") },
{ name: "address.zipcode", label: t("label.user_location_zipcode") },
{ name: "address.streetName", label: t("label.user_location_streetName") },
];
// React Query to fetch context variables
const { data: contextVars } = useFind({
entity: EntityType.CONTEXT_VAR,
});
// React Query to fetch contact information
const { data: contactInfos } = useFind(
{
entity: EntityType.SETTING,
},
{
params: {
where: {
group: "contact",
},
},
hasCount: false,
},
);
return (
<Accordion>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
{t("label.replacement_tokens")}
</AccordionSummary>
<AccordionDetails sx={{ maxHeight: "600px", overflowY: "scroll" }}>
<Typography variant="h6">{t("title.context_vars")}</Typography>
<List>
{(contextVars || []).map((v, index) => (
<ListItem key={index}>
<ListItemText
primary={`{context.vars.${v.name}}`}
secondary={`${v.label}`}
/>
</ListItem>
))}
</List>
<Typography variant="h6">{t("title.user_infos")}</Typography>
<List>
{userInfos.map((v, index) => (
<ListItem key={index}>
<ListItemText
primary={`{context.user.${v.name}}`}
secondary={`${v.label}`}
/>
</ListItem>
))}
</List>
<Typography variant="h6">{t("title.user_location")}</Typography>
<List>
{userLocation.map((v, index) => (
<ListItem key={index}>
<ListItemText
primary={`{context.user_location.${v.name}}`}
secondary={`${v.label}`}
/>
</ListItem>
))}
</List>
<Typography variant="h6">{t("title.contact_infos")}</Typography>
<List>
{(contactInfos || []).map((v, index) => (
<ListItem key={index}>
<ListItemText
primary={`{contact.${v.label}}`}
secondary={t("label." + v.label)}
/>
</ListItem>
))}
</List>
</AccordionDetails>
</Accordion>
);
}
ReplacementTokens.displayName = "ReplacementTokens";
export default ReplacementTokens;