Skip to content

Instantly share code, notes, and snippets.

@junaideqbal
Last active November 10, 2022 11:18
Show Gist options
  • Save junaideqbal/5dc3c03d753f2ccb55bf4f0776660bf9 to your computer and use it in GitHub Desktop.
Save junaideqbal/5dc3c03d753f2ccb55bf4f0776660bf9 to your computer and use it in GitHub Desktop.
Aura quick action confirmation dialogue
({
sendEmail : function(component, event, helper) {
component.set("v.loaded", false);
var recordId = component.get("v.recordId");
var recordIdStr = recordId.toString();
let action = component.get("c.updateSubscriptionField");
action.setParams({ "contactId" : recordId });
// Callback
action.setCallback(this, function(response) {
component.set("v.loaded", true);
var state = response.getState();
if (state === "SUCCESS") {
var contactId = response.getReturnValue();
if(component.get("v.location") !== 'visualforce'){
console.log("Location : "+component.get("v.location"));
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "The Email is scheduled successfully.",
"type": "success"
});
toastEvent.fire();
helper.redirecToRecord(contactId);
}else{
component.set("v.showSuccess",true);
component.set("v.successMessage","The Email is scheduled successfully.");
uJS.closeTab(contactId);
}
}else if(state === "ERROR"){
var errorMsg = response.getError()[0].message;
if(component.get("v.location") !== 'visualforce'){
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Error!",
"message": errorMsg,
"type": "error"
});
toastEvent.fire();
}else{
component.set("v.showError",true);
component.set("v.errorMessage",errorMsg);
}
}
});
$A.enqueueAction(action);
},
cancel: function(component, event, helper){
// Close the action panel
if(component.get("v.location") !== 'visualforce'){
var dismissActionPanel = $A.get("e.force:closeQuickAction");
dismissActionPanel.fire();
}else{
var recordId = component.get("v.recordId");
uJS.closeTab(recordId);
}
},
//$A.enqueueAction(action);
onCheck: function(cmp, evt) {
let checkCmp = cmp.find("checkbox");
let btnclickd = cmp.find("savebuttonid");
if(checkCmp.get("v.value")) {
btnclickd.set("v.disabled",false);
} else {
btnclickd.set("v.disabled",true);
}
}
});
({
redirecToRecord : function(contactId) {
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": contactId
});
navEvt.fire();
}
});
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" controller="ContactObjectHandler" >
<!--<aura:attribute name="recordId" type="String" />-->
<ltng:require scripts="{!$Resource.uJS}"></ltng:require>
<aura:attribute name="recordId" type="string" />
<aura:attribute name="location" type="string" />
<aura:attribute name="errorMessage" type="string" />
<aura:attribute name="successMessage" type="string" />
<aura:attribute name="loaded" type="Boolean" default="true" />
<aura:attribute name="showError" type="Boolean" default="false" />
<aura:attribute name="showSuccess" type="Boolean" default="false" />
<aura:html tag="style">
.cuf-content {
padding: 0rem !important;
}
.slds-p-around--medium {
padding: 0rem !important;
}
.slds-modal__content {
overflow: initial !important;
height: 99% !important;
max-height: 99% !important;
}
.slds-modal__container{
min-width: 100% !important;
width:99% !important;
padding-top: 35px!important;
padding-bottom: 35px!important;
overflow-y: scroll!important;
}
</aura:html>
<!-- Modal/Popup Box Header Starts here-->
<header class="slds-modal__header">
<h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">
Do you really want to re-subscribe the contact?
</h2>
</header>
<!--Modal Body Start here-->
<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
<p>Please be aware that based on the GDPR rules, customers can not be re-subscribed to any marketing email without their consent.</p>
<div class="slds-grid slds-m-around_small">
<ui:inputCheckbox aura:id="checkbox" labelClass="slds-p-horizontal--small slds-float--right slds-m-left_x-small slds-p-right_none" label="I confirm that this re-subscription request is on behalf of the contact." change="{!c.onCheck}"/>
<abbr class="slds-required" title="required">*</abbr>
</div>
</div>
<!--Modal Footer Start here-->
<footer class="slds-modal__footer">
<lightning:button variant="neutral" label="Cancel" onclick="{!c.cancel}" />
<lightning:button aura:id="savebuttonid" name="init" variant="brand" label="Send" onclick="{!c.sendEmail}" value="{!this}" disabled="true"/>
</footer>
<div class="loader">
<aura:if isTrue="{!v.loaded}">
<aura:set attribute="else">
<div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999999;">
<lightning:spinner alternativeText="Loading ..." variant="brand" />
</div>
</aura:set>
</aura:if>
</div>
<aura:if isTrue="{!v.showError}">
<br/><br/>
<div style="height:4rem">
<div class="slds-notify_container slds-is-relative">
<div class="slds-notify slds-notify_toast slds-theme_error" role="status">
<span class="slds-assistive-text">error</span>
<div class="slds-notify__content">
<h2 class="slds-text-heading_small ">{!v.errorMessage}</h2>
</div>
</div>
</div>
</div>
</aura:if>
<aura:if isTrue="{!v.showSuccess}">
<br/><br/>
<div style="height:4rem">
<div class="slds-notify_container slds-is-relative">
<div class="slds-notify slds-notify_toast slds-theme_success" role="status">
<span class="slds-assistive-text">success</span>
<div class="slds-notify__content">
<h2 class="slds-text-heading_small ">{!v.successMessage}</h2>
</div>
</div>
</div>
</div>
</aura:if>
</aura:component>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment