import { Box, Button, Card, Chip, CircularProgress, Container, Divider, Input, Typography, } from '@mui/joy' import moment from 'moment' import { useContext, useEffect, useState } from 'react' import { UserContext } from '../../contexts/UserContext' import Logo from '../../Logo' import { AcceptCircleMemberRequest, CancelSubscription, DeleteCircleMember, GetAllCircleMembers, GetCircleMemberRequests, GetSubscriptionSession, GetUserCircle, GetUserProfile, JoinCircle, LeaveCircle, } from '../../utils/Fetcher' import APITokenSettings from './APITokenSettings' import NotificationSetting from './NotificationSetting' import ThemeToggle from './ThemeToggle' const Settings = () => { const { userProfile, setUserProfile } = useContext(UserContext) const [userCircles, setUserCircles] = useState([]) const [circleMemberRequests, setCircleMemberRequests] = useState([]) const [circleInviteCode, setCircleInviteCode] = useState('') const [circleMembers, setCircleMembers] = useState([]) useEffect(() => { GetUserProfile().then(resp => { resp.json().then(data => { setUserProfile(data.res) }) }) GetUserCircle().then(resp => { resp.json().then(data => { setUserCircles(data.res ? data.res : []) }) }) GetCircleMemberRequests().then(resp => { resp.json().then(data => { setCircleMemberRequests(data.res ? data.res : []) }) }) GetAllCircleMembers() .then(res => res.json()) .then(data => { setCircleMembers(data.res ? data.res : []) }) }, []) useEffect(() => { const hash = window.location.hash if (hash) { const sharingSection = document.getElementById( window.location.hash.slice(1), ) if (sharingSection) { sharingSection.scrollIntoView({ behavior: 'smooth' }) } } }, []) const getSubscriptionDetails = () => { if (userProfile?.subscription === 'active') { return `You are currently subscribed to the Plus plan. Your subscription will renew on ${moment( userProfile?.expiration, ).format('MMM DD, YYYY')}.` } else if (userProfile?.subscription === 'canceled') { return `You have cancelled your subscription. Your account will be downgraded to the Free plan on ${moment( userProfile?.expiration, ).format('MMM DD, YYYY')}.` } else { return `You are currently on the Free plan. Upgrade to the Plus plan to unlock more features.` } } const getSubscriptionStatus = () => { if (userProfile?.subscription === 'active') { return `Plus` } else if (userProfile?.subscription === 'canceled') { if (moment().isBefore(userProfile?.expiration)) { return `Plus(until ${moment(userProfile?.expiration).format( 'MMM DD, YYYY', )})` } return `Free` } else { return `Free` } } if (userProfile === null) { return ( ) } return (
Sharing settings Your account is automatically connected to a Circle when you create or join one. Easily invite friends by sharing the unique Circle code or link below. You'll receive a notification below when someone requests to join your Circle. {userCircles[0]?.userRole === 'member' ? `You part of ${userCircles[0]?.name} ` : `You circle code is:`} {userCircles.length > 0 && userCircles[0]?.userRole === 'member' && ( )} Circle Members {circleMembers.map(member => ( {member.displayName.charAt(0).toUpperCase() + member.displayName.slice(1)} {member.userId === userProfile.id ? '(You)' : ''}{' '} {' '} {member.isActive ? member.role : 'Pending Approval'} {member.isActive ? ( Joined on {moment(member.createdAt).format('MMM DD, YYYY')} ) : ( Request to join{' '} {moment(member.updatedAt).format('MMM DD, YYYY')} )} {member.userId !== userProfile.id && member.isActive && ( )} ))} {circleMemberRequests.length > 0 && ( Circle Member Requests )} {circleMemberRequests.map(request => ( {request.displayName} wants to join your circle. ))} or if want to join someone else's Circle? Ask them for their unique Circle code or join link. Enter the code below to join their Circle. Enter Circle code: setCircleInviteCode(e.target.value)} size='lg' sx={{ width: '220px', mb: 1, }} />
Account Settings Change your account settings, including your password, display name Account Type : {getSubscriptionStatus()} {getSubscriptionDetails()} {userProfile?.subscription === 'active' && ( )}
Theme preferences Choose how the site looks to you. Select a single theme, or sync with your system and automatically switch between day and night themes.
) } export default Settings