Skip to content

Commit

Permalink
show result inline instead of using alert
Browse files Browse the repository at this point in the history
  • Loading branch information
tbjolset committed Apr 23, 2024
1 parent f269dc3 commit 5a4062d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ button:hover {
color: #f16363;
}

.success {
color: #528152;
}

.error {
padding: 1em;
}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
x-text="sending ? 'Sending...' : 'Send card'"
></button>
</div>
<div x-text="error" x-show="error" class="error"></div>
<div x-text="error || success" x-show="error || success" :class="error ? 'error' : 'success'"></div>

</section>
</main>
Expand Down
15 changes: 9 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ const model = {
},

async checkToken() {
this.botName = '';
this.botAvatar = '';
this.recipientName = '';
this.recipientAvatar = null;
this.error = false;
const token = this.botToken.trim();
try {
this.botName = '';
this.botAvatar = '';
const res = await whoAmI(token);
if (!res.ok) {
this.error = 'Token does not seem to be valid.';
Expand Down Expand Up @@ -171,29 +173,30 @@ const model = {

async send() {
this.error = false;
this.sending = true;
this.success = false;
this.sending = true;

try {
const text = 'Testing card from The Card Yard.'
const token = this.botToken;
const to = this.recipient;
const json = JSON.parse(this.currentJson);
const res = await sendWebexCard(token, to, text, json);
this.success = res.ok;
if (!res.ok) {
const json = await res.json();
console.log(res, json);
this.success = false;
this.error = res.status + ': ' + json.message;
}
else {
this.success = 'Card sent';
this.error = false;
this.rememberData();
alert('Card sent succesfully to ' + to);
}
}
catch(e) {
console.log(e);
this.error = e.reason;
this.success = false;
}
this.sending = false;
},
Expand Down

0 comments on commit 5a4062d

Please sign in to comment.