schon/storefront/src/composables/contact/useContactUs.js
Alexandr SaVBaD Waltz 9e837ba568 Features: 1) Implement composables for posts, products, categories, languages, and user deposits with lazy loading and GraphQL integration; 2) Add standalone pages for blog, product, store, and profile with scoped SCSS styling; 3) Add reusable UI components including header, footer, input, button, and textarea; 4) Introduce forms for contact and deposit functionality with validation and localization support; 5) Create GraphQL fragments for users, products, categories, company, orders, languages, and wishlist for efficient data fetching;
Fixes: 1) Correct missing semicolons in Pinia store definitions for cart, company, wishlist, and auth stores; 2) Refactor GraphQL queries to include fragments for improved modularity and readability; 3) Correct error handling in composables like `usePosts` and `useLanguages`;

Extra: Enhanced App.vue to include dynamic company info and language fetching on mount; Added scoped styles for new components and pages.
2025-05-28 15:35:42 +03:00

59 lines
No EOL
1.2 KiB
JavaScript

import {useMutation} from "@vue/apollo-composable";
import {ref} from "vue";
import {ElNotification} from "element-plus";
import {useI18n} from "vue-i18n";
import {CONTACT_US} from "@/graphql/mutations/contact.js";
export function useContactUs() {
const {t} = useI18n();
const { mutate: contactUsMutation } = useMutation(CONTACT_US);
const loading = ref(false);
async function contactUs(
name,
email,
phoneNumber,
subject,
message
) {
loading.value = true;
try {
const response = await contactUsMutation({
name,
email,
phoneNumber,
subject,
message
});
if (response.data?.contactUs.received) {
ElNotification({
message: t('popup.success.contactUs'),
type: 'success'
})
}
} catch (error) {
console.error("useContactUs error:", error);
const errorMessage = error.graphQLErrors?.[0]?.message ||
error.message ||
t('popup.errors.defaultError');
ElNotification({
title: t('popup.errors.main'),
message: errorMessage,
type: 'error'
});
} finally {
loading.value = false;
}
}
return {
contactUs,
loading
};
}