import React, { useEffect, useState } from "react"; import SwitchCom from "../../Helpers/SwitchCom"; import LoadingSpinner from "../../Spinners/LoadingSpinner"; import usersService from "../../../services/UsersService"; import localImgLoad from "../../../lib/localImgLoad"; import { toast } from "react-toastify"; import defaultImage from '../../../assets/images/banner-job-due.jpg' export default function NotificationSettingTab() { const api = new usersService(); const [accSettings, setAccSettings] = useState({loading: true, data: []}) // STATE TO HOLD ACCOUNT SETTINGS let [notificationChange, setNotificationChange] = useState({loading: false, uid: ''}) // const [updateNotification, setUpdateNotification] = useState(false); // const [uploadProduct, setUploadProduct] = useState(true); // const [saleProduct, setSaleProduct] = useState(true); // const [getProduct, setGetProduct] = useState(false); // const [authLevel, setAuthLevel] = useState(true); const NotificationInterfaceChange = (item) => { setAccSettings(prev => { let newAccSettings = prev.data.map(data => { if(data.uid == item.uid){ let newPrefValue = data.pref_value == null || data.pref_value == '0' ? '100' : '0' return {...data, pref_value: newPrefValue} }else{ return data } }) return {...prev, data: newAccSettings} }) } let handleNotificationChange = (item) => { // FUNCTION TO SET ACCOUNT SETTING setNotificationChange({loading: true, uid: item.uid}) let reqData = { // API PAYLOADS pref_id: item.pref_id, status: item.pref_value == null || item.pref_value == 0 ? 100 : 0 } api.setAccSettings(reqData).then(res => { if(res.status != 200 || res.data.internal_return < 0){ toast.error("unable to complete"); } toast.success("successful"); NotificationInterfaceChange(item) // CHANGES NOTIFICATION UI INTERFACE }).catch(errer => { toast.error("unable to complete"); }).finally(()=>{ setNotificationChange({loading: false, uid: {}}) // setTimeout(()=>{setNotificationChange({loading: false, uid: {}})},2000) }) } useEffect(()=>{ api.getAccSettings().then(res => { setAccSettings({loading: false, data: res.data?.result_list || []}) }).catch(errer => { setAccSettings({loading: false, data: []}) }) },[]) return (
{item.title}
{item.description}