Spaces:
Configuration error
Configuration error
File size: 6,248 Bytes
447ebeb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
import React, { useState, useEffect } from "react";
import {
Card,
Text,
Grid,
Button,
TextInput,
TableCell,
} from "@tremor/react";
import { Typography, message, Divider } from "antd";
import { serviceHealthCheck, setCallbacksCall } from "./networking";
import { EmailEventSettings } from "./email_events";
const { Title } = Typography;
interface EmailSettingsProps {
accessToken: string | null;
premiumUser: boolean;
alerts: any[];
}
const EmailSettings: React.FC<EmailSettingsProps> = ({
accessToken,
premiumUser,
alerts,
}) => {
const handleSaveEmailSettings = () => {
if (!accessToken) {
return;
}
let updatedVariables: Record<string, string> = {};
alerts
.filter((alert) => alert.name === "email")
.forEach((alert) => {
Object.entries(alert.variables ?? {}).forEach(([key, value]) => {
const inputElement = document.querySelector(`input[name="${key}"]`) as HTMLInputElement;
if (inputElement && inputElement.value) {
updatedVariables[key] = inputElement?.value;
}
});
});
console.log("updatedVariables", updatedVariables);
//filter out null / undefined values for updatedVariables
const payload = {
general_settings: {
alerting: ["email"],
},
environment_variables: updatedVariables,
};
try {
setCallbacksCall(accessToken, payload);
} catch (error) {
message.error("Failed to update alerts: " + error, 20);
}
message.success("Email settings updated successfully");
}
return (
<>
<div className="mt-6 mb-6">
<EmailEventSettings accessToken={accessToken} />
</div>
<Card>
<Title level={4}>Email Server Settings</Title>
<Text>
<a href="https://docs.litellm.ai/docs/proxy/email" target="_blank" style={{ color: "blue" }}> LiteLLM Docs: email alerts</a> <br/>
</Text>
<div className="flex w-full">
{alerts
.filter((alert) => alert.name === "email")
.map((alert, index) => (
<TableCell key={index}>
<ul>
<Grid numItems={2}>
{Object.entries(alert.variables ?? {}).map(([key, value]) => (
<li key={key} className="mx-2 my-2">
{ premiumUser!= true && (key === "EMAIL_LOGO_URL" || key === "EMAIL_SUPPORT_CONTACT") ? (
<div>
<a
href="https://forms.gle/W3U4PZpJGFHWtHyA9"
target="_blank"
>
<Text className="mt-2">
{" "}
✨ {key}
</Text>
</a>
<TextInput
name={key}
defaultValue={value as string}
type="password"
disabled={true}
style={{ width: "400px" }}
/>
</div>
) : (
<div>
<Text className="mt-2">{key}</Text>
<TextInput
name={key}
defaultValue={value as string}
type="password"
style={{ width: "400px" }}
/>
</div>
)}
{/* Added descriptions for input fields */}
<p style={{ fontSize: "small", fontStyle: "italic" }}>
{key === "SMTP_HOST" && (
<div style={{ color: "gray" }}>
Enter the SMTP host address, e.g. `smtp.resend.com`
<span style={{ color: "red" }}> Required * </span>
</div>
)}
{key === "SMTP_PORT" && (
<div style={{ color: "gray" }}>
Enter the SMTP port number, e.g. `587`
<span style={{ color: "red" }}> Required * </span>
</div>
)}
{key === "SMTP_USERNAME" && (
<div style={{ color: "gray" }}>
Enter the SMTP username, e.g. `username`
<span style={{ color: "red" }}> Required * </span>
</div>
)}
{key === "SMTP_PASSWORD" && (
<span style={{ color: "red" }}> Required * </span>
)}
{key === "SMTP_SENDER_EMAIL" && (
<div style={{ color: "gray" }}>
Enter the sender email address, e.g. `[email protected]`
<span style={{ color: "red" }}> Required * </span>
</div>
)}
{key === "TEST_EMAIL_ADDRESS" && (
<div style={{ color: "gray" }}>
Email Address to send `Test Email Alert` to. example: `[email protected]`
<span style={{ color: "red" }}> Required * </span>
</div>
)
}
{key === "EMAIL_LOGO_URL" && (
<div style={{ color: "gray" }}>
(Optional) Customize the Logo that appears in the email, pass a url to your logo
</div>
)
}
{key === "EMAIL_SUPPORT_CONTACT" && (
<div style={{ color: "gray" }}>
(Optional) Customize the support email address that appears in the email. Default is [email protected]
</div>
)
}
</p>
</li>
))}
</Grid>
</ul>
</TableCell>
))}
</div>
<Button
className="mt-2"
onClick={() => handleSaveEmailSettings()}
>
Save Changes
</Button>
<Button
onClick={() =>
accessToken && serviceHealthCheck(accessToken, "email")
}
className="mx-2"
>
Test Email Alerts
</Button>
</Card>
</>
);
};
export default EmailSettings; |