Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addProduct () {
- if (this.productName === '' || this.category === '' || this.price === 0 || this.contactInformation === '' || this.productDetails === '' || this.files.length === 0) {
- this.$q.notify({
- icon: 'close',
- message: 'Fields can not be empty.',
- timeout: 800,
- color: 'negative',
- textColor: 'white',
- position: 'bottom-left'
- });
- } else {
- this.$q.dialog({
- title: 'Confirm',
- message: 'Are you sure you want to continue?',
- ok: {
- color: 'brown'
- },
- cancel: {
- color: 'brown',
- flat: true
- },
- persistent: true
- })
- .onOk(async () => {
- const docRef = await this.firebase.firestore().collection('products').add({
- productName: this.productName,
- category: this.category,
- price: this.price,
- contactInformation: this.contactInformation,
- productDetails: this.productDetails,
- displayName: this.user.displayName,
- phoneNumber: this.user.phoneNumber,
- uid: this.user.uid,
- createdAt: Date.now()
- });
- const images = [];
- for (const file of files) {
- const storageRef = this.firebase.storage().ref('products/' + this.user.uid + '/' + docRef.id + '/' + file.name);
- const snapshot = await storageRef.put(file);
- const downloadURL = await snapshot.ref.getDownloadURL();
- images.push(downloadURL);
- }
- const data = await this.firebase.firestore().collection('products').doc(docRef.id).update({
- images: images
- });
- this.$refs.uploader.$data.files = [];
- this.productName = ''
- this.category = ''
- this.price = 0
- this.contactInformation = ''
- this.productDetails = ''
- this.$q.notify({
- icon: 'check',
- message: 'You have successfully added.',
- timeout: 800,
- color: 'brown',
- textColor: 'white',
- position: 'bottom-left'
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement