2023-12-09 15:47:03 +01:00
|
|
|
<template>
|
2024-04-15 19:39:03 +02:00
|
|
|
<modal
|
|
|
|
|
:show="show"
|
|
|
|
|
max-width="lg"
|
|
|
|
|
@close="close"
|
|
|
|
|
>
|
|
|
|
|
<text-input
|
|
|
|
|
ref="companyName"
|
|
|
|
|
label="Company Name"
|
|
|
|
|
name="name"
|
|
|
|
|
:required="true"
|
|
|
|
|
:form="form"
|
|
|
|
|
help="Name that will appear on invoices"
|
|
|
|
|
/>
|
|
|
|
|
<text-input
|
|
|
|
|
label="Email"
|
|
|
|
|
name="email"
|
|
|
|
|
native-type="email"
|
|
|
|
|
:required="true"
|
|
|
|
|
:form="form"
|
|
|
|
|
help="Where invoices will be sent"
|
|
|
|
|
/>
|
|
|
|
|
<v-button
|
|
|
|
|
:loading="form.busy || loading"
|
|
|
|
|
:disabled="form.busy || loading ? true : null"
|
|
|
|
|
class="mt-6 block mx-auto"
|
|
|
|
|
:arrow="true"
|
|
|
|
|
@click="saveDetails"
|
2023-12-09 15:47:03 +01:00
|
|
|
>
|
|
|
|
|
Go to checkout
|
|
|
|
|
</v-button>
|
|
|
|
|
</modal>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-04-15 19:39:03 +02:00
|
|
|
import { computed } from "vue"
|
|
|
|
|
import TextInput from "../../forms/TextInput.vue"
|
|
|
|
|
import VButton from "~/components/global/VButton.vue"
|
2023-12-09 15:47:03 +01:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: { VButton, TextInput },
|
|
|
|
|
props: {
|
|
|
|
|
show: {
|
|
|
|
|
type: Boolean,
|
2024-04-15 19:39:03 +02:00
|
|
|
default: false,
|
2023-12-09 15:47:03 +01:00
|
|
|
},
|
|
|
|
|
plan: {
|
|
|
|
|
type: String,
|
2024-04-15 19:39:03 +02:00
|
|
|
default: "pro",
|
2023-12-09 15:47:03 +01:00
|
|
|
},
|
|
|
|
|
yearly: {
|
|
|
|
|
type: Boolean,
|
2024-04-15 19:39:03 +02:00
|
|
|
default: true,
|
|
|
|
|
},
|
2023-12-09 15:47:03 +01:00
|
|
|
},
|
2024-04-15 19:39:03 +02:00
|
|
|
emits: ['close'],
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-15 19:39:03 +02:00
|
|
|
setup() {
|
2023-12-09 15:47:03 +01:00
|
|
|
const authStore = useAuthStore()
|
|
|
|
|
return {
|
2024-04-15 19:39:03 +02:00
|
|
|
user: computed(() => authStore.user),
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
data: () => ({
|
2023-12-24 20:19:59 +01:00
|
|
|
form: useForm({
|
2024-04-15 19:39:03 +02:00
|
|
|
name: "",
|
|
|
|
|
email: "",
|
2023-12-09 15:47:03 +01:00
|
|
|
}),
|
2024-04-15 19:39:03 +02:00
|
|
|
loading: false,
|
2023-12-09 15:47:03 +01:00
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
computed: {},
|
|
|
|
|
|
|
|
|
|
watch: {
|
2024-04-15 19:39:03 +02:00
|
|
|
user() {
|
2023-12-09 15:47:03 +01:00
|
|
|
this.updateUser()
|
|
|
|
|
},
|
2024-04-15 19:39:03 +02:00
|
|
|
show() {
|
2023-12-09 15:47:03 +01:00
|
|
|
// Wait for modal to open and focus on first field
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (this.$refs.companyName) {
|
2024-04-15 19:39:03 +02:00
|
|
|
this.$refs.companyName.$el.querySelector("input").focus()
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
}, 300)
|
|
|
|
|
|
|
|
|
|
this.loading = false
|
2024-04-15 19:39:03 +02:00
|
|
|
},
|
2023-12-09 15:47:03 +01:00
|
|
|
},
|
|
|
|
|
|
2024-04-15 19:39:03 +02:00
|
|
|
mounted() {
|
2023-12-09 15:47:03 +01:00
|
|
|
this.updateUser()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
2024-04-15 19:39:03 +02:00
|
|
|
updateUser() {
|
2023-12-09 15:47:03 +01:00
|
|
|
if (this.user) {
|
|
|
|
|
this.form.name = this.user.name
|
|
|
|
|
this.form.email = this.user.email
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-04-15 19:39:03 +02:00
|
|
|
saveDetails() {
|
2023-12-09 15:47:03 +01:00
|
|
|
if (this.form.busy) return
|
2024-04-15 19:39:03 +02:00
|
|
|
this.form.put("subscription/update-customer-details").then(() => {
|
2023-12-09 15:47:03 +01:00
|
|
|
this.loading = true
|
2024-04-15 19:39:03 +02:00
|
|
|
opnFetch(
|
|
|
|
|
"/subscription/new/" +
|
|
|
|
|
this.plan +
|
|
|
|
|
"/" +
|
|
|
|
|
(!this.yearly ? "monthly" : "yearly") +
|
|
|
|
|
"/checkout/with-trial",
|
|
|
|
|
)
|
|
|
|
|
.then((data) => {
|
|
|
|
|
window.location = data.checkout_url
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
useAlert().error(error.data.message)
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
this.loading = false
|
|
|
|
|
this.close()
|
|
|
|
|
})
|
2023-12-09 15:47:03 +01:00
|
|
|
})
|
|
|
|
|
},
|
2024-04-15 19:39:03 +02:00
|
|
|
close() {
|
|
|
|
|
this.$emit("close")
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
</script>
|