芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/rentandbuyrealty.com/web/src/Components/User/UserProfile.jsx
"use client" import React, { useEffect, useState } from "react"; import dynamic from "next/dynamic.js"; import { useRef } from "react"; import { useSelector } from "react-redux"; import { Fcmtoken, settingsData } from "@/store/reducer/settingsSlice"; import LocationSearchBox from "@/Components/Location/LocationSearchBox"; import { UpdateProfileApi } from "@/store/actions/campaign"; import { loadUpdateUserData } from "@/store/reducer/authSlice"; import { useRouter } from "next/router"; import toast from "react-hot-toast"; import { placeholderImage, translate } from "@/utils"; import { languageData } from "@/store/reducer/languageSlice"; import Image from "next/image"; import Swal from "sweetalert2"; const VerticleLayout = dynamic(() => import('../../../src/Components/AdminLayout/VerticleLayout.jsx'), { ssr: false }) const UserProfile = () => { const userData = useSelector((state) => state.User_signup); const userProfileData = userData?.data?.data; const navigate = useRouter(); const FcmToken = useSelector(Fcmtoken) const [formData, setFormData] = useState({ fullName: userProfileData?.name, email: userProfileData?.email, phoneNumber: userProfileData?.mobile, address: userProfileData?.address, aboutMe: userProfileData?.about_me, facebook: userProfileData?.facebook_id, instagram: userProfileData?.instagram_id, pintrest: userProfileData?.pintrest_id, twiiter: userProfileData?.twiiter_id, profileImage: userProfileData?.profile, }); const fileInputRef = useRef(null); const [uploadedImage, setUploadedImage] = useState(userProfileData?.profile || null); const lang = useSelector(languageData); useEffect(() => { }, [lang]); const SettingsData = useSelector(settingsData); const PlaceHolderImg = SettingsData?.web_placeholder_logo; const handleImageUpload = (e) => { const file = e.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = (e) => { setFormData({ ...formData, profileImage: file, }); setUploadedImage(e.target.result); }; reader.readAsDataURL(file); } }; const handleInputChange = (e) => { const { name, value } = e.target; setFormData({ ...formData, [name]: value }); }; const handleUploadButtonClick = () => { fileInputRef.current.click(); // Trigger the file input click event }; const handleLocationSelected = (locationData) => { setFormData({ ...formData, selectedLocation: locationData, }); }; const handlePhoneNumberChange = (e) => { const value = e.target.value; if (/^\d*$/.test(value)) { setFormData({ ...formData, phoneNumber: value }); } }; const isLoggedIn = useSelector((state) => state.User_signup); const userCurrentId = isLoggedIn && isLoggedIn.data ? isLoggedIn.data.data.id : null; const handleUpdateProfile = (e) => { e.preventDefault(); if (SettingsData.demo_mode) { Swal.fire({ title: "Opps !", text: "This Action is Not Allowed in Demo Mode", icon: "warning", showCancelButton: false, customClass: { confirmButton: 'Swal-confirm-buttons', cancelButton: "Swal-cancel-buttons" }, confirmButtonText: "OK", }); return false; } UpdateProfileApi({ userid: userCurrentId, name: formData.fullName, email: formData.email, mobile: formData.phoneNumber, address: formData.address, profile: formData.profileImage, latitude: formData.selectedLocation?.lat, longitude: formData.selectedLocation?.lng, about_me: formData.aboutMe ? formData.aboutMe : "", facebook_id: formData.facebook ? formData.facebook : "", twiiter_id: formData.twiiter ? formData.twiiter : "", instagram_id: formData.instagram ? formData.instagram : "", pintrest_id: formData.pintrest ? formData.pintrest : "", fcm_id: FcmToken, notification: "1", city: formData.selectedLocation?.city, state: formData.selectedLocation?.state, country: formData.selectedLocation?.country, onSuccess: (response) => { toast.success(translate("profileupdate")); loadUpdateUserData(response.data); navigate.push("/"); setFormData({ fullName: "", email: "", phoneNumber: "", address: "", aboutMe: "", facebook: "", instagram: "", pintrest: "", twiiter: "", }); }, onError: (error) => { toast.error(error); } }); }; return (
{translate("myProfile")}
{translate("personalInfo")}
{translate("uploadImg")}
{translate("Note:")}
{translate("fullName")}
{translate("email")}
{translate("phoneNumber")}
{translate("location")}
{translate("address")}
{translate("aboutMe")}
{translate("aboutMe")}
{translate("socialMedia")}
{translate("facebook")}
{translate("insta")}
{translate("pinterest")}
{translate("twitter")}
{translate("updateProfile")}
); }; export default UserProfile;