Forum Discussion

hlio's avatar
hlio
Mentor
7 years ago

Delay loading a Component on a page until initial endpoint call has completed

We want to use an end point to contact Zendesk via API to then assign a role back into Lithium for a user.
We want a component (Contact US) in the page to display different options based on that newly assigned role, but we currently have to reload the page to have it display the options.
 
Is there a way to cause that component to wait without doing a whole page reload? We would like to wait to load the component until that endpoint has completed and then display the options in one complete experience. 
 
Curious if there are any ideas.
 
  • hlio

     

    It can be implemented by using component and endpoint, the Component code should be written in JS (for synchronous ajax call) to Endpoint.

     

    Endpoint should do all the stuff like,

    1. 3rd party API Call  ( Zendesk)

    2. Assign the role to a user and return the roleName to component (Contact US)  for further Processing.

     

    The component should make sync ajax call to endpoint using this it will halt the code execution until the endpoint returns the response.

     

    There is no any other way to delay the code execution in Freemarker. It can only be achieve using JS in component.

     

  • I'm assuming you mean, the role is assigned while the user is on the Contact page. For example, they click something and the role is assigned in the background via an endpoint... after that, things on the page will change without a reload.

     

    In that case, you could:

    • Load part of the component but with CSS set to display none (or show it part of it, if helpful)
      • Retrieve data from another endpoint based on the new role, add to component, then change the CSS to display it

    You could send a parameter into the role endpoint and trigger the other endpoint, like a callback.