-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add smtp form to global settings (#1372)
- Loading branch information
1 parent
b71cc42
commit b95fe2d
Showing
6 changed files
with
216 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
assets/src/components/settings/global/GlobalSettingsSMTP.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import { | ||
Button, | ||
Card, | ||
Flex, | ||
Switch, | ||
Toast, | ||
ValidatedInput, | ||
} from '@pluralsh/design-system' | ||
import { useDeploymentSettings } from 'components/contexts/DeploymentSettingsContext' | ||
import { GqlError } from 'components/utils/Alert' | ||
import { ScrollablePage } from 'components/utils/layout/ScrollablePage' | ||
import { | ||
SmtpSettingsAttributes, | ||
useUpdateDeploymentSettingsMutation, | ||
} from 'generated/graphql' | ||
import { FormEvent, useState } from 'react' | ||
import { useTheme } from 'styled-components' | ||
|
||
import { cleanSmtpForm } from '../usermanagement/email/EmailSettingsForm' | ||
|
||
export function GlobalSettingsSMTP() { | ||
const theme = useTheme() | ||
const { smtp } = useDeploymentSettings() | ||
const [form, setForm] = useState<SmtpSettingsAttributes>({ | ||
...(cleanSmtpForm(smtp) || defaultForm), | ||
password: '', | ||
}) | ||
const [showToast, setShowToast] = useState(false) | ||
|
||
const [mutation, { loading, error }] = useUpdateDeploymentSettingsMutation({ | ||
variables: { | ||
attributes: { | ||
smtp: form, | ||
}, | ||
}, | ||
onCompleted: () => { | ||
setShowToast(true) | ||
setForm({ | ||
...form, | ||
password: '', | ||
}) | ||
}, | ||
}) | ||
|
||
const allowSubmit = !!( | ||
form.server && | ||
form.port && | ||
form.sender && | ||
form.user && | ||
form.password | ||
) | ||
|
||
const handleSubmit = (e: FormEvent) => { | ||
e.preventDefault() | ||
mutation() | ||
} | ||
|
||
return ( | ||
<ScrollablePage heading="SMTP Settings"> | ||
<form onSubmit={handleSubmit}> | ||
<Card | ||
css={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: theme.spacing.medium, | ||
padding: theme.spacing.xlarge, | ||
}} | ||
> | ||
{error && <GqlError error={error} />} | ||
<ValidatedInput | ||
label="Server" | ||
placeholder="smtp.sendrid.net" | ||
value={form.server || ''} | ||
onChange={(e) => | ||
setForm({ | ||
...form, | ||
server: e.target.value, | ||
}) | ||
} | ||
/> | ||
<ValidatedInput | ||
label="Port" | ||
placeholder="587" | ||
value={form.port || ''} | ||
onChange={(e) => | ||
setForm({ | ||
...form, | ||
port: parseInt(e.target.value), | ||
}) | ||
} | ||
/> | ||
<ValidatedInput | ||
label="Sender" | ||
hint="From address for outgoing emails" | ||
value={form.sender || ''} | ||
onChange={(e) => | ||
setForm({ | ||
...form, | ||
sender: e.target.value, | ||
}) | ||
} | ||
/> | ||
<ValidatedInput | ||
label="User" | ||
hint="Username for SMTP authentication" | ||
value={form.user || ''} | ||
onChange={(e) => | ||
setForm({ | ||
...form, | ||
user: e.target.value, | ||
}) | ||
} | ||
/> | ||
<ValidatedInput | ||
label="Password" | ||
hint="Password for SMTP authentication" | ||
type="password" | ||
value={form.password || ''} | ||
onChange={(e) => | ||
setForm({ | ||
...form, | ||
password: e.target.value, | ||
}) | ||
} | ||
/> | ||
<Flex justify="space-between"> | ||
<Switch | ||
checked={form.ssl} | ||
onChange={(checked) => | ||
setForm({ | ||
...form, | ||
ssl: checked, | ||
}) | ||
} | ||
css={{ | ||
...theme.partials.text.body2Bold, | ||
color: theme.colors.text, | ||
}} | ||
> | ||
SSL | ||
</Switch> | ||
<Button | ||
type="submit" | ||
disabled={!allowSubmit} | ||
loading={loading} | ||
> | ||
Update | ||
</Button> | ||
</Flex> | ||
</Card> | ||
</form> | ||
<Toast | ||
severity="success" | ||
css={{ | ||
margin: theme.spacing.large, | ||
}} | ||
show={showToast} | ||
onClose={() => setShowToast(false)} | ||
> | ||
SMTP settings updated successfully | ||
</Toast> | ||
</ScrollablePage> | ||
) | ||
} | ||
|
||
const defaultForm = { | ||
server: '', | ||
port: 587, | ||
sender: '', | ||
user: '', | ||
ssl: false, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.