IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Unverified Commit a425481f authored by Brian Picciano's avatar Brian Picciano Committed by GitHub
Browse files

Merge pull request #15 from my-conservation-life/feature-register-access-code

Feature register access code
parents 80ca04ef 855d0447
......@@ -2,6 +2,8 @@
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="createAssetDefinition">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Create Asset Definitions</masterLabel>
<description>Define and create assets definitions for use in various projects</description>
<targets>
<target>lightning__AppPage</target>
</targets>
......
.success {
color: darkgreen;
}
.error {
color: darkred;
}
\ No newline at end of file
<template>
<lightning-card>
<div class="slds-m-around_medium">
<lightning-input type="text" name="accessCode" label="Input Access Code" onchange={saveAttribute}>
</lightning-input>
<br />
<lightning-button variant="success" label="Submit" title="Success" onclick={registerAccessCode}>
</lightning-button>
<p if:true={hasError} class="error">Unable to claim access code. Please make sure it is inputted correctly
and with the correct capitalization.</p>
<p if:true={hasSuccess} class="success">Sucessfuly claimed access code.</p>
</div>
</lightning-card>
</template>
\ No newline at end of file
/* eslint-disable @lwc/lwc/no-async-operation */
import { LightningElement, track } from 'lwc';
import { updateRecord } from 'lightning/uiRecordApi';
import USER_ID from '@salesforce/user/Id';
import ID_FIELD from '@salesforce/schema/Access_Code__c.Id';
import DONOR_FIELD from '@salesforce/schema/Access_Code__c.Donor__c';
export default class RegisterAccessCode extends LightningElement {
MESSAGE_TIMEOUT = 5500;
accessCode;
@track hasError = false;
@track hasSuccess = false;
registerAccessCode() {
if (!this.accessCode) this.showError();
const fields = {};
fields[ID_FIELD.fieldApiName] = this.accessCode;
fields[DONOR_FIELD.fieldApiName] = USER_ID;
updateRecord({ fields })
.then(() => {
this.showSuccess();
})
.catch(error => {
this.showError();
console.error(error);
});
}
/**
* Event handler to save the user inputted value to this property's attributes.
*
* @param {Event} e - a change event dispatched by each input
*/
saveAttribute(e) {
const ele = e.srcElement;
const name = ele.name;
const value = ele.value;
this[name] = value;
}
showSuccess() {
this.hasError = false;
this.hasSuccess = true;
setTimeout(() => {
this.hasSuccess = false;
}, this.MESSAGE_TIMEOUT);
}
showError() {
this.hasError = true;
this.hasSuccess = false;
setTimeout(() => {
this.hasError = false;
}, this.MESSAGE_TIMEOUT);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="registerAccessCode">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Register Access Codes</masterLabel>
<description>Registers access codes to the user's account</description>
<targets>
<target>lightning__AppPage</target>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
</LightningComponentBundle>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment