Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added dynamic links to buttons #3180

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/containers/HSM/HSM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
const [validatingURL, setValidatingURL] = useState<boolean>(false);
const [isUrlValid, setIsUrlValid] = useState<any>();
const [templateType, setTemplateType] = useState<string | null>(CALL_TO_ACTION);
const [dynamicUrlParams, setDynamicUrlParams] = useState<any>({
urlType: 'Static',
sampleSuffix: '',
});
const [sampleMessages, setSampleMessages] = useState({
type: 'TEXT',
location: null,
Expand Down Expand Up @@ -160,15 +164,25 @@
};

// Creating payload for button template
const getButtonTemplatePayload = () => {
const buttons = templateButtons.reduce((result: any, button) => {
const getButtonTemplatePayload = (urlType: string, sampleSuffix: string) => {
const buttons = templateButtons.reduce((result: any, button: any) => {
const { type: buttonType, value, title }: any = button;

if (templateType === CALL_TO_ACTION) {
const typeObj: any = {
phone_number: 'PHONE_NUMBER',
url: 'URL',
};
const obj: any = { type: typeObj[buttonType], text: title, [buttonType]: value };
let obj: any = { type: typeObj[buttonType], text: title, [buttonType]: value };

if (buttonType === 'url' && urlType === 'Dynamic') {
obj = {

Check warning on line 179 in src/containers/HSM/HSM.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/HSM/HSM.tsx#L179

Added line #L179 was not covered by tests
type: typeObj[buttonType],
text: title,
[buttonType]: `${value}{{1}}`,
example: [`${value}${sampleSuffix}`],
};
}
result.push(obj);
}

Expand All @@ -192,6 +206,10 @@
};
};

const handleDynamicParamsChange = (value: any) => {
setDynamicUrlParams(value);

Check warning on line 210 in src/containers/HSM/HSM.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/HSM/HSM.tsx#L210

Added line #L210 was not covered by tests
};

const setStates = ({
isActive: isActiveValue,
language: languageIdValue,
Expand Down Expand Up @@ -269,6 +287,7 @@

const setPayload = (payload: any) => {
let payloadCopy = { ...payload, isHsm: true };
const { urlType, sampleSuffix } = dynamicUrlParams;
if (isEditing) {
payloadCopy.shortcode = payloadCopy.newShortcode;
} else {
Expand All @@ -278,7 +297,7 @@
payloadCopy.languageId = payload.language.id;
payloadCopy.example = getExampleFromBody(payloadCopy.body, variables);
if (isAddButtonChecked && templateType) {
const templateButtonData = getButtonTemplatePayload();
const templateButtonData = getButtonTemplatePayload(urlType, sampleSuffix);
Object.assign(payloadCopy, { ...templateButtonData });
}
if (payloadCopy.type) {
Expand Down Expand Up @@ -515,6 +534,8 @@
onRemoveClick: removeTemplateButtons,
onInputChange: handeInputChange,
onTemplateTypeChange: handleTemplateTypeChange,
dynamicUrlParams,
onDynamicParamsChange: handleDynamicParamsChange,
},
{
component: AutoComplete,
Expand Down
25 changes: 20 additions & 5 deletions src/containers/TemplateOptions/TemplateOptions.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

.CallToActionWrapper {
composes: Font;
display: flex;
flex-direction: column;
gap: 0.5rem;
}

.CallToActionWrapper > div {
Expand Down Expand Up @@ -42,7 +45,7 @@

.RadioStyles {
composes: Font;
margin-bottom: 12px;
margin-bottom: 0.5rem;
}

.RadioLabel > span:last-child {
Expand All @@ -57,10 +60,6 @@
display: block !important;
}

.FormControl {
margin-bottom: 17px;
}

.FormControl > p {
margin-left: 12px;
}
Expand Down Expand Up @@ -115,3 +114,19 @@
.Button {
margin-top: 7px;
}

.FieldLabel {
font-weight: 500;
font-size: 16px;
line-height: 18px;
color: #555555;
padding-bottom: 14px;
}

.DefaultInputRoot {
background-color: #ffffff;
}

.StartAdornment {
padding-right: 0.5rem;
}
5 changes: 5 additions & 0 deletions src/containers/TemplateOptions/TemplateOptions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const props = (isAddButtonChecked: any, templateType: any, inputFields: any, for
templateType,
inputFields,
form,
dynamicUrlParams: {
urlType: 'Static',
sampleSuffix: '',
},
onDynamicParamsChange: () => {},
});

const callToAction = { type: 'phone_number', value: '', title: '' };
Expand Down
69 changes: 65 additions & 4 deletions src/containers/TemplateOptions/TemplateOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { RadioGroup, FormControlLabel, Radio, TextField, FormHelperText, FormControl } from '@mui/material';
import {
RadioGroup,
FormControlLabel,
Radio,
TextField,
FormHelperText,
FormControl,
Autocomplete,
Typography,
} from '@mui/material';
import { FieldArray } from 'formik';

import { Button } from 'components/UI/Form/Button/Button';
Expand All @@ -14,31 +23,36 @@
isAddButtonChecked: boolean;
templateType: string | null;
inputFields: Array<any>;
form: { touched: any; errors: any; values: any };
form: { touched: any; errors: any; values: any; setFieldValue: any };
onAddClick: any;
onRemoveClick: any;
onInputChange: any;
onTemplateTypeChange: any;
disabled: any;
dynamicUrlParams: any;
onDynamicParamsChange: any;
}
export const TemplateOptions = ({
isAddButtonChecked,
templateType,
inputFields,
form: { touched, errors, values },
form: { touched, errors },
onAddClick,
onRemoveClick,
onTemplateTypeChange,
onInputChange,
disabled = false,
dynamicUrlParams,
onDynamicParamsChange,
}: TemplateOptionsProps) => {
const buttonTitle = 'Button Title';
const buttonValue = 'Button Value';
const buttonTitles: any = {
CALL_TO_ACTION: 'Call to action',
QUICK_REPLY: 'Quick Reply',
};

const options = ['Static', 'Dynamic'];
const { urlType, sampleSuffix } = dynamicUrlParams;
const handleAddClick = (helper: any, type: boolean) => {
const obj = type ? { type: '', value: '', title: '' } : { value: '' };
helper.push(obj);
Expand Down Expand Up @@ -133,6 +147,23 @@
) : null}
</div>
</div>
{type === 'url' && (
<div className={styles.TextFieldWrapper}>
<Autocomplete
options={options}
classes={{ inputRoot: styles.DefaultInputRoot }}
renderInput={(params) => <TextField {...params} label="Select URL Type" />}

Check warning on line 155 in src/containers/TemplateOptions/TemplateOptions.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/TemplateOptions/TemplateOptions.tsx#L155

Added line #L155 was not covered by tests
clearIcon={false}
value={urlType}
onChange={(event: any, newValue: string | null) => {
onDynamicParamsChange({

Check warning on line 159 in src/containers/TemplateOptions/TemplateOptions.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/TemplateOptions/TemplateOptions.tsx#L159

Added line #L159 was not covered by tests
...dynamicUrlParams,
urlType: newValue,
});
}}
/>
</div>
)}
<div className={styles.TextFieldWrapper} data-testid="buttonTitle">
<FormControl fullWidth error={isError('title')} className={styles.FormControl}>
<TextField
Expand Down Expand Up @@ -167,7 +198,37 @@
) : null}
</FormControl>
</div>
{urlType === 'Dynamic' && type === 'url' && (
<div>
<FormControl fullWidth error={isError('title')} className={styles.FormControl}>
<TextField
disabled={disabled}
label={'Sample Suffix'}
className={styles.TextField}
slotProps={{
input: {
startAdornment: (
<Typography
variant="body2"
color="textSecondary"
className={styles.StartAdornment}
>{`{{1}}`}</Typography>
),
},
}}
onChange={(event) =>
onDynamicParamsChange({

Check warning on line 220 in src/containers/TemplateOptions/TemplateOptions.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/TemplateOptions/TemplateOptions.tsx#L220

Added line #L220 was not covered by tests
...dynamicUrlParams,
sampleSuffix: event.target.value,
})
}
value={sampleSuffix}
/>
</FormControl>
</div>
)}
</div>

<div className={styles.Button}>
{inputFields.length === index + 1 && inputFields.length !== 2 ? addButton(arrayHelpers, true) : null}
</div>
Expand Down
Loading