2021-02-24 22:35:24 +00:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
<template>
|
2021-07-08 20:06:07 +01:00
|
|
|
<div class="add-coupon__input-container">
|
|
|
|
<div v-if="!showConfirmMessage">
|
|
|
|
<div class="add-coupon__input-wrapper">
|
|
|
|
<img
|
|
|
|
class="add-coupon__input-icon"
|
|
|
|
:class="{'signup-view': isSignupView}"
|
|
|
|
src="@/../static/images/account/billing/coupon.png"
|
|
|
|
alt="Coupon"
|
|
|
|
>
|
|
|
|
<HeaderlessInput
|
|
|
|
:label="inputLabel"
|
|
|
|
placeholder="Enter Coupon Code"
|
|
|
|
class="add-coupon__input"
|
|
|
|
height="52px"
|
|
|
|
:with-icon="true"
|
|
|
|
@setData="setCouponCode"
|
|
|
|
/>
|
|
|
|
<CheckIcon
|
|
|
|
v-if="isCodeValid"
|
|
|
|
class="add-coupon__check"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<ValidationMessage
|
|
|
|
class="add-coupon__valid-message"
|
|
|
|
success-message="Successfully applied coupon code."
|
|
|
|
:error-message="errorMessage"
|
|
|
|
:is-valid="isCodeValid"
|
|
|
|
:show-message="showValidationMessage"
|
2021-02-24 22:35:24 +00:00
|
|
|
/>
|
2021-07-08 20:06:07 +01:00
|
|
|
<VButton
|
|
|
|
v-if="!isSignupView"
|
|
|
|
class="add-coupon__apply-button"
|
|
|
|
label="Apply Coupon Code"
|
|
|
|
width="85%"
|
|
|
|
height="44px"
|
|
|
|
:on-press="couponCheck"
|
2021-02-24 22:35:24 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2021-07-08 20:06:07 +01:00
|
|
|
<div v-if="showConfirmMessage">
|
|
|
|
<p class="add-coupon__confirm-message">
|
|
|
|
By applying this coupon you will override your existing coupon.
|
|
|
|
Are you sure you want to remove your current coupon and replace it with this new coupon?
|
|
|
|
</p>
|
|
|
|
<div class="add-coupon__button-wrapper">
|
|
|
|
<VButton
|
|
|
|
class="add-coupon__confirm-button"
|
|
|
|
label="Yes"
|
|
|
|
width="250px"
|
|
|
|
height="44px"
|
|
|
|
:on-press="applyCouponCode"
|
|
|
|
/>
|
|
|
|
<VButton
|
|
|
|
class="add-coupon__back-button"
|
|
|
|
label="Back"
|
|
|
|
width="250px"
|
|
|
|
height="44px"
|
|
|
|
is-blue-white="true"
|
|
|
|
:on-press="toggleConfirmMessage"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-24 22:35:24 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-08-06 21:14:33 +01:00
|
|
|
import { Component, Vue } from 'vue-property-decorator';
|
2021-02-24 22:35:24 +00:00
|
|
|
|
|
|
|
import HeaderlessInput from '@/components/common/HeaderlessInput.vue';
|
|
|
|
import ValidationMessage from '@/components/common/ValidationMessage.vue';
|
|
|
|
import VButton from '@/components/common/VButton.vue';
|
|
|
|
|
|
|
|
import CloseIcon from '@/../static/images/common/closeCross.svg';
|
|
|
|
import CheckIcon from '@/../static/images/common/validCheck.svg';
|
|
|
|
|
2021-07-08 20:06:07 +01:00
|
|
|
import { PaymentsHttpApi } from '@/api/payments';
|
2021-02-24 22:35:24 +00:00
|
|
|
import { RouteConfig } from '@/router';
|
2021-08-06 21:14:33 +01:00
|
|
|
import { PAYMENTS_ACTIONS } from '@/store/modules/payments';
|
2021-02-24 22:35:24 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
VButton,
|
|
|
|
HeaderlessInput,
|
|
|
|
CloseIcon,
|
|
|
|
CheckIcon,
|
|
|
|
ValidationMessage,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class AddCouponCodeInput extends Vue {
|
2021-06-22 01:09:56 +01:00
|
|
|
private showValidationMessage = false;
|
|
|
|
private errorMessage = '';
|
|
|
|
private isCodeValid = false;
|
|
|
|
|
|
|
|
private couponCode = '';
|
2021-02-24 22:35:24 +00:00
|
|
|
|
2021-07-08 20:06:07 +01:00
|
|
|
private showConfirmMessage = false;
|
|
|
|
|
|
|
|
private readonly payments: PaymentsHttpApi = new PaymentsHttpApi();
|
|
|
|
|
2021-02-24 22:35:24 +00:00
|
|
|
/**
|
|
|
|
* Signup view requires some unque styling and element text.
|
|
|
|
*/
|
|
|
|
public get isSignupView(): boolean {
|
|
|
|
return this.$route.name === RouteConfig.Register.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns label for input if in signup view
|
|
|
|
* Depending on view.
|
|
|
|
*/
|
|
|
|
public get inputLabel(): string | void {
|
|
|
|
return this.isSignupView ? 'Add Coupon' : '';
|
|
|
|
}
|
|
|
|
|
2021-06-22 01:09:56 +01:00
|
|
|
public setCouponCode(value: string): void {
|
|
|
|
this.couponCode = value;
|
2021-02-24 22:35:24 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 20:06:07 +01:00
|
|
|
/**
|
|
|
|
* Toggles showing of coupon code replace confirmation message
|
|
|
|
*/
|
|
|
|
public toggleConfirmMessage(): void {
|
|
|
|
this.showConfirmMessage = !this.showConfirmMessage;
|
|
|
|
}
|
|
|
|
|
2021-06-22 01:09:56 +01:00
|
|
|
/**
|
|
|
|
* Check if coupon code is valid
|
|
|
|
*/
|
2021-07-08 20:06:07 +01:00
|
|
|
public async applyCouponCode(): Promise<void> {
|
2021-06-22 01:09:56 +01:00
|
|
|
try {
|
2021-08-06 21:14:33 +01:00
|
|
|
await this.$store.dispatch(PAYMENTS_ACTIONS.APPLY_COUPON_CODE, this.couponCode);
|
2021-07-08 20:06:07 +01:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
if (this.showConfirmMessage) {
|
|
|
|
this.toggleConfirmMessage();
|
|
|
|
}
|
2021-06-22 01:09:56 +01:00
|
|
|
this.errorMessage = error.message;
|
|
|
|
this.isCodeValid = false;
|
|
|
|
this.showValidationMessage = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2021-07-08 20:06:07 +01:00
|
|
|
if (this.showConfirmMessage) {
|
|
|
|
this.toggleConfirmMessage();
|
|
|
|
}
|
2021-06-22 01:09:56 +01:00
|
|
|
this.isCodeValid = true;
|
|
|
|
this.showValidationMessage = true;
|
|
|
|
}
|
2021-07-08 20:06:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if user has a coupon code applied to their account before applying
|
|
|
|
*/
|
|
|
|
public async couponCheck(): Promise<void> {
|
|
|
|
try {
|
2021-08-06 21:14:33 +01:00
|
|
|
if (this.$store.state.paymentsModule.coupon) {
|
2021-07-08 20:06:07 +01:00
|
|
|
this.toggleConfirmMessage();
|
|
|
|
} else {
|
|
|
|
this.applyCouponCode();
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
this.errorMessage = error.message;
|
|
|
|
this.isCodeValid = false;
|
|
|
|
this.showValidationMessage = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 22:35:24 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
|
|
.add-coupon {
|
|
|
|
|
|
|
|
&__input-wrapper {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
&__valid-message {
|
|
|
|
position: relative;
|
|
|
|
top: 15px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&__apply-button {
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
margin: 0 auto;
|
|
|
|
bottom: 40px;
|
2021-06-22 01:09:56 +01:00
|
|
|
background: #2683ff;
|
2021-02-24 22:35:24 +00:00
|
|
|
|
|
|
|
&:hover {
|
2021-06-22 01:09:56 +01:00
|
|
|
background: #0059d0;
|
2021-02-24 22:35:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&__check {
|
|
|
|
position: absolute;
|
|
|
|
right: 15px;
|
|
|
|
bottom: 15px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&__input-icon {
|
|
|
|
position: absolute;
|
|
|
|
top: 27px;
|
|
|
|
z-index: 23;
|
|
|
|
left: 25px;
|
|
|
|
width: 25.01px;
|
|
|
|
height: 16.67px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&__input-icon.signup-view {
|
|
|
|
top: 63px;
|
|
|
|
}
|
2021-07-08 20:06:07 +01:00
|
|
|
|
|
|
|
&__confirm-message {
|
|
|
|
font-family: 'font_regular', sans-serif;
|
|
|
|
font-size: 18px;
|
|
|
|
margin-top: 35px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&__button-wrapper {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-evenly;
|
|
|
|
margin-top: 30px;
|
|
|
|
}
|
2021-02-24 22:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|