2

So I have an app, which contains a button directing people to my 'Ccenter', normally this would bring me to a .DE domain, but I want to create the ability for it to redirect to the .AT instance of my site.

I can decide which domain the button should bring me to by looking at my recipient data, which always contains a country specific email address.

'recipient_email':data.ticket.recipient,

I thought the best way for this to work is an If/Else Statement on the Button itself, where I could use if “data.ticket.recipient.contains?(.de)” to ensure the button links to the .DE app instance, otherwise link to the .AT instance.

I'm unsure how to structure that statement within my code, and would appreciate some pointers or advice on if this is the best way to achieve what I'm aiming for.

Current code:

client.get(`ticket.customField:${cCenterCaseIdFieldName}`).then((result) => {
          updateDataPoints(result, data, cCenterCaseIdFieldName);
          const recipientEmail = data.ticket.recipient;
          const zendeskID = data.ticket.id;
          const cCenterUrlAustria = getAustrianCcenterUrl(zendeskID)
          const cCenterUrl = getCcenterUrl(zendeskID);
          const collapse = $('#collapseExample')
          $("#myBtnToCcenter").click(() => openModalPopup(cCenterUrl));
          $("#myBtnToAustrianCcenter").click(() => openModalPopup(cCenterUrlAustria));
         

Modal Pop Up Which Results From Button Click:

  function openModalPopup(locationUrl) {
  const modalOptions = {
    location: 'modal',
    url: locationUrl,
    size: {
      width:  '80vw',
      height: '80vh'
    }
  };
3
  • So what you want is to use one button only, instead of both #myBtnToCcenter and #myBtnToAustrianCcenter? Commented Oct 13, 2021 at 13:27
  • @AnisR. exactly, theres no room in this mini-app for a third button Commented Oct 13, 2021 at 13:30
  • We can just set the url to search for specific string you are looking for and update the constant accordingly using a ternary as below const recipientEmail = data.ticket.recipient; const cCenterUrl = recipientEmail.includes(".de") ? getCcenterUrl(zendeskID) : getAustrianCcenterUrl(zendeskID); $("#myBtnToCcenter").click(() => openModalPopup(cCenterUrl)); Commented Oct 13, 2021 at 13:38

2 Answers 2

2

i guess you could just do sth. like this:

const recipientEmail = data.ticket.recipient;
var cCenterUrl;
if(recipientEmail.indexOf(".de") > 0) {
    cCenterUrl = getCcenterUrl(zendeskID);
}else{
    cCenterUrl = getAustrianCcenterUrl(zendeskID)
}
$("#myBtnToCcenter").click(() => openModalPopup(cCenterUrl));

and just use 1 button, if cCenterUrl can change during runtime, u cannot use const of course

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer, the only issue here for me is, that cCenterUrl becomes undefined due to being in the if/else statement.
ok, with my update it should definetly work
1

One way would be to get the correct URL first, then set the onClick handler accordingly. Something like:

var url = data.ticket.recipient.includes(".de") ? getCcenterUrl(zendeskID) : getAustrianCcenterUrl(zendeskID);

$("#myBtnToCcenter").click(() => openModalPopup(url));

Side note: The includes() function is case-sensitive. If you are not sure of the case (upper/lowercase) of the data.ticket.recipient string, then you can do

data.ticket.recipient.toLowerCase().includes(".de".toLowerCase())

instead of data.ticket.recipient.includes(".de").

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.