setDialogOpen(false)}
+ onConfirm={handleConfirmLeave}
+ title="Confirm Leave"
+ message={`Are you sure you want the bot to leave ${selectedGuild?.name}?`}
+ />
);
};
diff --git a/frontend/src/components/Login.js b/frontend/src/components/Login.js
index 7a3dc4c..da07ed5 100644
--- a/frontend/src/components/Login.js
+++ b/frontend/src/components/Login.js
@@ -1,5 +1,6 @@
import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
+import { Button, Container, Paper, Typography, Box } from '@mui/material';
const Login = () => {
const navigate = useNavigate();
@@ -16,10 +17,27 @@ const Login = () => {
};
return (
-
-
Login
-
-
+
+
+
+ Welcome!
+
+
+ Login with your Discord account to continue
+
+
+
+
+
+
);
};
diff --git a/frontend/src/components/ServerSettings.js b/frontend/src/components/ServerSettings.js
index 8e67206..e939317 100644
--- a/frontend/src/components/ServerSettings.js
+++ b/frontend/src/components/ServerSettings.js
@@ -1,9 +1,11 @@
import React, { useState, useEffect } from 'react';
import { useParams, useNavigate, useLocation } from 'react-router-dom';
import axios from 'axios';
-import { Button, Typography, Card, CardContent, Box, IconButton } from '@mui/material';
+import { Button, Typography, Box, IconButton, Switch, Select, MenuItem, FormControl, FormControlLabel, Radio, RadioGroup, TextField, Accordion, AccordionSummary, AccordionDetails } from '@mui/material';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
+import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import UserSettings from './UserSettings';
+import ConfirmDialog from './ConfirmDialog';
const ServerSettings = () => {
const { guildId } = useParams();
@@ -13,6 +15,25 @@ const ServerSettings = () => {
const [isBotInServer, setIsBotInServer] = useState(false);
const [clientId, setClientId] = useState(null);
const [server, setServer] = useState(null);
+ const [dialogOpen, setDialogOpen] = useState(false);
+ const [channels, setChannels] = useState([]);
+ const [welcomeLeaveSettings, setWelcomeLeaveSettings] = useState({
+ welcome: {
+ enabled: false,
+ channel: '',
+ message: 'Welcome to the server, {user}!',
+ customMessage: '',
+ },
+ leave: {
+ enabled: false,
+ channel: '',
+ message: '{user} has left the server.',
+ customMessage: '',
+ },
+ });
+
+ const defaultWelcomeMessages = ["Welcome to the server, {user}!", "Hey {user}, welcome!", "{user} has joined the party!"];
+ const defaultLeaveMessages = ["{user} has left the server.", "Goodbye, {user}.", "We'll miss you, {user}."];
useEffect(() => {
if (location.state && location.state.guild) {
@@ -43,9 +64,78 @@ const ServerSettings = () => {
.then(response => {
setClientId(response.data.clientId);
});
+
+ // Fetch channels
+ axios.get(`http://localhost:3002/api/servers/${guildId}/channels`)
+ .then(response => {
+ setChannels(response.data);
+ });
+
+ // Fetch welcome/leave settings
+ axios.get(`http://localhost:3002/api/servers/${guildId}/welcome-leave-settings`)
+ .then(response => {
+ if (response.data) {
+ setWelcomeLeaveSettings(response.data);
+ }
+ });
}, [guildId, location.state]);
+ const handleSettingUpdate = (newSettings) => {
+ axios.post(`http://localhost:3002/api/servers/${guildId}/welcome-leave-settings`, newSettings)
+ .then(response => {
+ if (response.data.success) {
+ setWelcomeLeaveSettings(newSettings);
+ }
+ });
+ }
+
+ const handleToggleChange = (type) => (event) => {
+ const newSettings = { ...welcomeLeaveSettings };
+ newSettings[type].enabled = event.target.checked;
+ handleSettingUpdate(newSettings);
+ };
+
+ const handleChannelChange = (type) => (event) => {
+ const newSettings = { ...welcomeLeaveSettings };
+ newSettings[type].channel = event.target.value;
+ handleSettingUpdate(newSettings);
+ };
+
+ const handleMessageOptionChange = (type) => (event) => {
+ const newSettings = { ...welcomeLeaveSettings };
+ if (event.target.value !== 'custom') {
+ newSettings[type].message = event.target.value;
+ handleSettingUpdate(newSettings);
+ } else {
+ const tempSettings = { ...welcomeLeaveSettings };
+ // Set message to custom message to get the radio button to select custom
+ tempSettings[type].message = tempSettings[type].customMessage;
+ setWelcomeLeaveSettings(tempSettings);
+ }
+ };
+
+ const handleCustomMessageChange = (type) => (event) => {
+ const newSettings = { ...welcomeLeaveSettings };
+ newSettings[type].customMessage = event.target.value;
+ setWelcomeLeaveSettings(newSettings);
+ };
+
+ const handleApplyCustomMessage = (type) => () => {
+ const newSettings = { ...welcomeLeaveSettings };
+ newSettings[type].message = newSettings[type].customMessage;
+ handleSettingUpdate(newSettings);
+ };
+
+ const getMessageValue = (type) => {
+ const currentMessage = welcomeLeaveSettings[type].message;
+ const defaultMessages = type === 'welcome' ? defaultWelcomeMessages : defaultLeaveMessages;
+ if (defaultMessages.includes(currentMessage)) {
+ return currentMessage;
+ }
+ return 'custom';
+ }
+
const togglePingCommand = () => {
const newSettings = { ...settings, pingCommand: !settings.pingCommand };
axios.post(`http://localhost:3002/api/servers/${guildId}/settings`, newSettings)
@@ -63,6 +153,20 @@ const ServerSettings = () => {
window.open(url, '_blank');
};
+ const handleLeaveBot = () => {
+ setDialogOpen(true);
+ };
+
+ const handleConfirmLeave = async () => {
+ try {
+ await axios.post(`http://localhost:3002/api/servers/${guildId}/leave`);
+ setIsBotInServer(false);
+ } catch (error) {
+ console.error('Error leaving server:', error);
+ }
+ setDialogOpen(false);
+ };
+
const handleBack = () => {
navigate('/dashboard');
}
@@ -78,7 +182,9 @@ const ServerSettings = () => {
{server ? `Server Settings for ${server.name}` : 'Loading...'}
{isBotInServer ? (
- The bot is already in this server.
+
) : (