diff --git a/resources/scripts/api/admin/settings/getMailSettings.ts b/resources/scripts/api/admin/settings/getMailSettings.ts new file mode 100644 index 00000000..5eac1d67 --- /dev/null +++ b/resources/scripts/api/admin/settings/getMailSettings.ts @@ -0,0 +1,6 @@ +import http from '@/api/http'; +import { MailSettings } from './updateMailSettings'; + +export default (): Promise => { + return http.get('/api/application/settings/mail').then(response => response.data); +}; diff --git a/resources/scripts/api/admin/settings/updateMailSettings.ts b/resources/scripts/api/admin/settings/updateMailSettings.ts new file mode 100644 index 00000000..67546765 --- /dev/null +++ b/resources/scripts/api/admin/settings/updateMailSettings.ts @@ -0,0 +1,15 @@ +import http from '@/api/http'; + +export interface MailSettings { + 'mail:mailers:smtp:host': string; + 'mail:mailers:smtp:port': number; + 'mail:mailers:smtp:encryption': string; + 'mail:mailers:smtp:username': string; + 'mail:mailers:smtp:password': string; + 'mail:from:address': string; + 'mail:from:name': string; +} + +export default (settings: MailSettings): Promise => { + return http.patch('/api/application/settings/mail', settings); +}; diff --git a/resources/scripts/components/admin/settings/MailSettings.tsx b/resources/scripts/components/admin/settings/MailSettings.tsx index 1e63eecc..65d71a3e 100644 --- a/resources/scripts/components/admin/settings/MailSettings.tsx +++ b/resources/scripts/components/admin/settings/MailSettings.tsx @@ -1,102 +1,268 @@ -import { Form, Formik } from 'formik'; -import tw from 'twin.macro'; +import { Form, Formik, FormikHelpers } from 'formik'; -import AdminBox from '@/components/admin/AdminBox'; -import Button from '@/components/elements/Button'; -import Field, { FieldRow } from '@/components/elements/Field'; -import Label from '@/components/elements/Label'; -import Select from '@/components/elements/Select'; +import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Button } from '@/components/ui/button'; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from '@/components/ui/select'; +import { Loader2 } from 'lucide-react'; +import updateMailSettings, { MailSettings } from '@/api/admin/settings/updateMailSettings'; +import { useEffect, useState } from 'react'; +import Error, { LaravelError } from '@/components/elements/error/Error'; +import { Skeleton } from '@/components/ui/skeleton'; +import getMailSettings from '@/api/admin/settings/getMailSettings'; +import { flushSync } from 'react-dom'; -export default () => { - const submit = () => { - // +const MailSettingsForm = ({ settings }: { settings: MailSettings }) => { + const [error, setError] = useState(undefined); + + const submit = (settings: MailSettings, { setSubmitting }: FormikHelpers) => { + setError(undefined); + + updateMailSettings(settings) + .then(() => { + setSubmitting(false); + }) + .catch(error => { + setError(error.response?.data); + setSubmitting(false); + }); }; return ( - {({ isSubmitting, isValid }) => ( + {({ isSubmitting, isValid, values }) => (
- - - - -
- - -
-
+ + + Mail Settings + Configure how the Panel should send emails to users. + + + {error && } - - - - - - - - - -
- -
-
- -
-
+ +
)}
); }; + +export default () => { + const [settings, setSettings] = useState(undefined); + + useEffect(() => { + const fetchSettings = async () => { + try { + const fetchedSettings = await getMailSettings(); + if (document.startViewTransition) { + document.startViewTransition(() => { + flushSync(() => { + setSettings(fetchedSettings); + }); + }); + } else { + setSettings(fetchedSettings); // Fallback if startViewTransition is not available + } + } catch (error) { + console.error('Error fetching mail settings:', error); + } + }; + + fetchSettings(); + }, []); + + if (!settings) { + return ( + + + Mail Settings + Configure how the Panel should send emails to users. + + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + + +
+ ); + } else { + return ; + } +};