You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

214 lines
6.4 KiB

<template>
<modal name="add-contact-modal" width="100%" :clickToClose="false">
<div class="tw-p-[30px] md:tw-p-0 tw-h-full tw-overflow-auto">
<div
class="modal-header tw-flex tw-justify-start tw-items-center tw-mb-[30px] md:tw-mb-[50px] xl:tw-justify-between">
<div
class="tw-flex tw-justify-between tw-w-full tw-text-[18px] tw-font-bold tw-leading-[26px] md:tw-text-[20px]">
{{ $t("userProfile.addContactInfo") }}
</div>
<button class="close tw-transition tw-btn-md" @click="$modal.hide('add-contact-modal')"></button>
</div>
<div
class="modal-content tw-grid tw-grid-cols-1 tw-gap-y-[20px] tw-mb-[30px] md:tw-grid-cols-2 md:tw-gap-x-[60px] md:tw-mb-[60px]">
<div class="element">
<elementInput :input="{
id: 'FirstName',
label: 'userProfile.firstName',
required: true,
type: 'text',
}" :default="formData.first_name" :validation="validation.first_name" @change="formData.first_name = $event">
</elementInput>
</div>
<div class="element">
<elementInput :input="{
id: 'LastName',
label: 'userProfile.lastName',
required: true,
type: 'text',
}" :default="formData.last_name" :validation="validation.last_name" @change="formData.last_name = $event">
</elementInput>
</div>
<div class="element">
<elementInput :input="{
id: 'Email',
label: 'Email',
required: true,
type: 'email',
}" :default="formData.email" :validation="validation.email" @change="formData.email = $event">
</elementInput>
</div>
<div class="element">
<label class="tw-block tw-mb-[10px]"><span>{{ $t("Phone") }}<span class="required">*</span></span></label>
<vue-country-code class="d-none" enabledCountryCode :enabledFlags="false" v-model="countryCode"
@onSelect="showCode"></vue-country-code>
<vue-phone-number-input color="#EF5A5A" valid-color="#EE9546" :border-radius="5" no-flags no-example
v-model="formData.phone_number" @update="getPhoneData"></vue-phone-number-input>
</div>
</div>
<div class="modal-footer md:tw-flex md:tw-flex-row-reverse md:tw-justify-start md:tw-items-center">
<button
class="tw-text-[18px] tw-transition tw-btn-md tw-bg-primary-1 tw-w-full tw-py-[12px] tw-rounded-[16px] tw-mb-[10px] md:tw-w-fit md:tw-px-[24px] md:tw-mb-0 md:hover:tw-bg-primary-2"
@click="save">
{{ $t("userProfile.add") }}
</button>
<button
class="tw-text-[18px] tw-transition tw-btn-md tw-text-primary-1 tw-w-full tw-py-[12px] tw-rounded-[16px] md:tw-w-fit md:tw-px-[24px] md:tw-mr-[10px]"
@click="reset">
{{ $t("Clear") }}
</button>
</div>
</div>
</modal>
</template>
<script>
import elementInput from "@/components/newComponent/form/ElementInput";
import Swal from "sweetalert2";
import is from "is_js";
export default {
name: "AddContactModal",
components: {
elementInput,
},
data() {
return {
formData: {
first_name: "",
last_name: "",
email: "",
country_code: "",
phone_number: "",
},
validation: {
first_name: true,
last_name: true,
email: true,
phone_number: true,
},
isValid: true,
countryCode: "",
phoneValid: false,
errors: null,
};
},
mounted() { },
methods: {
reset() {
this.formData = {
first_name: "",
last_name: "",
email: "",
country_code: "",
phone_number: "",
};
(this.countryCode = ""), (this.phoneValid = false);
},
getPhoneData(phoneData) {
this.countryCode = phoneData.countryCode;
this.phoneValid = phoneData.isValid;
},
showCode(object) {
this.formData.country_code = object.dialCode;
},
save() {
this.validators();
if (this.validators() && this.phoneValid) {
const patchData = JSON.parse(JSON.stringify(this.formData));
this.$axios
.post(
`/member/contacts?jwt=${this.$auth.$storage.getUniversal("jwt").token
}`,
patchData
)
.then((result) => {
if (result.status == 200) {
this.$emit("update", true);
this.reset();
this.$modal.hide("add-contact-modal");
}
})
.catch((err) => {
console.log(err);
});
}
},
validators() {
if (is.empty(this.formData.first_name)) {
this.validation.first_name = false;
} else {
this.validation.first_name = true;
}
if (is.empty(this.formData.last_name)) {
this.validation.last_name = false;
} else {
this.validation.last_name = true;
}
if (is.empty(this.formData.email) || is.not.email(this.formData.email)) {
this.validation.email = false;
} else {
this.validation.email = true;
}
if (
is.empty(this.formData.phone_number) &&
is.number(this.formData.phone_number)
) {
this.validation.phone_number = false;
} else {
this.validation.phone_number = true;
}
this.errors = Object.entries(this.validation).filter(
(e) => e[1] == false
);
if (this.errors.length > 0) {
return false;
} else {
return true;
}
},
},
};
</script>
<style lang="scss" scoped>
.close {
// position: absolute;
right: 30px;
top: 32px;
background-image: url("~/assets/svg/close.svg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
width: 14px;
height: 14px;
@media screen and (min-width: 768px) {
right: 40px;
top: 40px;
}
}
.v--modal-overlay::v-deep {
.v--modal {
width: 100% !important;
height: 100vh !important;
@media screen and (min-width: 768px) {
padding: 40px;
width: max-content;
height: max-content !important;
border-radius: 30px;
}
}
.v--modal-box {
height: 100vh !important;
overflow: auto;
@media screen and (min-width: 768px) {
padding: 40px;
width: max-content;
height: max-content !important;
}
}
}
</style>