Skip to content

Commit 5d78bf1

Browse files
committed
fix: email template info
1 parent 5874949 commit 5d78bf1

File tree

3 files changed

+185
-28
lines changed

3 files changed

+185
-28
lines changed

dashboard/src/components/UpdateEmailTemplateModal.tsx

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,20 @@ import {
1717
Text,
1818
useDisclosure,
1919
useToast,
20+
Alert,
21+
AlertIcon,
22+
Collapse,
23+
Box,
24+
TableContainer,
25+
Table,
26+
Thead,
27+
Tr,
28+
Th,
29+
Tbody,
30+
Td,
31+
Code,
2032
} from '@chakra-ui/react';
21-
import { FaPlus } from 'react-icons/fa';
33+
import { FaPlus, FaAngleDown, FaAngleUp } from 'react-icons/fa';
2234
import { useClient } from 'urql';
2335
import { Editor } from 'react-draft-wysiwyg';
2436
import { EditorState, convertToRaw, Modifier } from 'draft-js';
@@ -50,6 +62,7 @@ interface UpdateEmailTemplateInputPropTypes {
5062
interface templateVariableDataTypes {
5163
text: string;
5264
value: string;
65+
description: string;
5366
}
5467

5568
interface emailTemplateDataType {
@@ -94,6 +107,9 @@ const UpdateEmailTemplate = ({
94107
const onEditorStateChange = (editorState: EditorState) => {
95108
setEditorState(editorState);
96109
};
110+
const [isDynamicVariableInfoOpen, setIsDynamicVariableInfoOpen] =
111+
useState<boolean>(false);
112+
97113
const inputChangehandler = (inputType: string, value: any) => {
98114
if (inputType !== EmailTemplateInputDataFields.EVENT_NAME) {
99115
setValidator({
@@ -202,27 +218,29 @@ const UpdateEmailTemplate = ({
202218
useEffect(() => {
203219
const updatedTemplateVariables = Object.entries(
204220
emailTemplateVariables
205-
).reduce((acc, varData): any => {
221+
).reduce((acc, [key, val]): any => {
206222
if (
207223
(templateData[EmailTemplateInputDataFields.EVENT_NAME] !==
208224
emailTemplateEventNames['Verify Otp'] &&
209-
varData[1] === emailTemplateVariables.otp) ||
225+
val === emailTemplateVariables.otp) ||
210226
(templateData[EmailTemplateInputDataFields.EVENT_NAME] ===
211227
emailTemplateEventNames['Verify Otp'] &&
212-
varData[1] === emailTemplateVariables.verification_url)
228+
val === emailTemplateVariables.verification_url)
213229
) {
214230
return acc;
215231
}
216232
return [
217233
...acc,
218234
{
219-
text: varData[0],
220-
value: varData[1],
235+
text: key,
236+
value: val.value,
237+
description: val.description,
221238
},
222239
];
223240
}, []);
224241
setTemplateVariables(updatedTemplateVariables);
225242
}, [templateData[EmailTemplateInputDataFields.EVENT_NAME]]);
243+
226244
return (
227245
<>
228246
{view === UpdateModalViews.ADD ? (
@@ -256,6 +274,73 @@ const UpdateEmailTemplate = ({
256274
borderColor="gray.200"
257275
p="5"
258276
>
277+
<Alert
278+
status="info"
279+
onClick={() =>
280+
setIsDynamicVariableInfoOpen(!isDynamicVariableInfoOpen)
281+
}
282+
borderRadius="5"
283+
marginY={5}
284+
cursor="pointer"
285+
fontSize="sm"
286+
>
287+
<AlertIcon />
288+
<Flex
289+
width="100%"
290+
justifyContent="space-between"
291+
alignItems="center"
292+
>
293+
<Box width="85%">
294+
<b>Note:</b> You can add set of dynamic variables to subject
295+
and email body. Click here to see the set of dynamic
296+
variables.
297+
</Box>
298+
{isDynamicVariableInfoOpen ? <FaAngleUp /> : <FaAngleDown />}
299+
</Flex>
300+
</Alert>
301+
<Collapse
302+
style={{
303+
width: '100%',
304+
}}
305+
in={isDynamicVariableInfoOpen}
306+
>
307+
<TableContainer
308+
background="gray.100"
309+
borderRadius={5}
310+
height={200}
311+
width="100%"
312+
overflowY="auto"
313+
overflowWrap="break-word"
314+
>
315+
<Table variant="simple">
316+
<Thead>
317+
<Tr>
318+
<Th>Variable</Th>
319+
<Th>Description</Th>
320+
</Tr>
321+
</Thead>
322+
<Tbody>
323+
{templateVariables.map((i) => (
324+
<Tr key={i.text}>
325+
<Td>
326+
<Code fontSize="sm">{`{{${i.text}}}`}</Code>
327+
</Td>
328+
<Td>
329+
<Text
330+
size="sm"
331+
fontSize="sm"
332+
overflowWrap="break-word"
333+
width="100%"
334+
>
335+
{i.description}
336+
</Text>
337+
</Td>
338+
</Tr>
339+
))}
340+
</Tbody>
341+
</Table>
342+
</TableContainer>
343+
</Collapse>
259344
<Flex
260345
width="100%"
261346
justifyContent="space-between"
@@ -334,14 +419,21 @@ const UpdateEmailTemplate = ({
334419
border: '1px solid #d9d9d9',
335420
borderRadius: '5px',
336421
marginTop: '2%',
337-
height: '35vh',
422+
height: '30vh',
338423
}}
339424
mention={{
340425
separator: ' ',
341426
trigger: '{',
342427
suggestions: templateVariables,
343428
}}
344429
/>
430+
<Alert status="info" marginY={5} borderRadius={5}>
431+
<AlertIcon />
432+
<Box fontSize="sm">
433+
<b>Note:</b> In order to use dynamic variables with link and
434+
images you can put them as part of URL in editor section.
435+
</Box>
436+
</Alert>
345437
</Flex>
346438
</ModalBody>
347439
<ModalFooter>

dashboard/src/components/UpdateWebhookModal.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ const UpdateWebhookModal = ({
569569
status="info"
570570
onClick={() => setIsShowingPayload(!isShowingPayload)}
571571
borderRadius="5"
572+
cursor="pointer"
573+
fontSize="sm"
572574
>
573575
<AlertIcon />
574576
<Flex

dashboard/src/constants.ts

Lines changed: 84 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,90 @@ export enum webhookVerifiedStatus {
207207
}
208208

209209
export const emailTemplateVariables = {
210-
'user.id': '{.user.id}}',
211-
'user.email': '{.user.email}}',
212-
'user.given_name': '{.user.given_name}}',
213-
'user.family_name': '{.user.family_name}}',
214-
'user.signup_methods': '{.user.signup_methods}}',
215-
'user.email_verified': '{.user.email_verified}}',
216-
'user.picture': '{.user.picture}}',
217-
'user.roles': '{.user.roles}}',
218-
'user.middle_name': '{.user.middle_name}}',
219-
'user.nickname': '{.user.nickname}}',
220-
'user.preferred_username': '{.user.preferred_username}}',
221-
'user.gender': '{.user.gender}}',
222-
'user.birthdate': '{.user.birthdate}}',
223-
'user.phone_number': '{.user.phone_number}}',
224-
'user.phone_number_verified': '{.user.phone_number_verified}}',
225-
'user.created_at': '{.user.created_at}}',
226-
'user.updated_at': '{.user.updated_at}}',
227-
'organization.name': '{.organization.name}}',
228-
'organization.logo': '{.organization.logo}}',
229-
verification_url: '{.verification_url}}',
230-
otp: '{.otp}}',
210+
'user.id': {
211+
description: `User identifier`,
212+
value: '{.user.id}}',
213+
},
214+
'user.email': {
215+
description: 'User email address',
216+
value: '{.user.email}}',
217+
},
218+
'user.given_name': {
219+
description: `User first name`,
220+
value: '{.user.given_name}}',
221+
},
222+
'user.family_name': {
223+
description: `User last name`,
224+
value: '{.user.family_name}}',
225+
},
226+
'user.middle_name': {
227+
description: `Middle name of user`,
228+
value: '{.user.middle_name}}',
229+
},
230+
'user.nickname': {
231+
description: `Nick name of user`,
232+
value: '{.user.nickname}}',
233+
},
234+
'user.preferred_username': {
235+
description: `Username, by default it is email`,
236+
value: '{.user.preferred_username}}',
237+
},
238+
'user.signup_methods': {
239+
description: `Comma separated list of methods using which user has signed up`,
240+
value: '{.user.signup_methods}}',
241+
},
242+
'user.email_verified': {
243+
description: `Whether email is verified or not`,
244+
value: '{.user.email_verified}}',
245+
},
246+
'user.picture': {
247+
description: `URL of the user profile picture`,
248+
value: '{.user.picture}}',
249+
},
250+
'user.roles': {
251+
description: `Comma separated list of roles assigned to user`,
252+
value: '{.user.roles}}',
253+
},
254+
'user.gender': {
255+
description: `Gender of user`,
256+
value: '{.user.gender}}',
257+
},
258+
'user.birthdate': {
259+
description: `BirthDate of user`,
260+
value: '{.user.birthdate}}',
261+
},
262+
'user.phone_number': {
263+
description: `Phone number of user`,
264+
value: '{.user.phone_number}}',
265+
},
266+
'user.phone_number_verified': {
267+
description: `Whether phone number is verified or not`,
268+
value: '{.user.phone_number_verified}}',
269+
},
270+
'user.created_at': {
271+
description: `User created at time`,
272+
value: '{.user.created_at}}',
273+
},
274+
'user.updated_at': {
275+
description: `Last updated time at user`,
276+
value: '{.user.updated_at}}',
277+
},
278+
'organization.name': {
279+
description: `Organization name`,
280+
value: '{.organization.name}}',
281+
},
282+
'organization.logo': {
283+
description: `Organization logo`,
284+
value: '{.organization.logo}}',
285+
},
286+
verification_url: {
287+
description: `Verification URL in case of events other than verify otp`,
288+
value: '{.verification_url}}',
289+
},
290+
otp: {
291+
description: `OTP sent during login with Multi factor authentication`,
292+
value: '{.otp}}',
293+
},
231294
};
232295

233296
export const webhookPayloadExample: string = `{

0 commit comments

Comments
 (0)