Add 'send opt-in mail' link to subscriber modal UI

This commit is contained in:
Kailash Nadh 2020-02-09 17:17:58 +05:30
parent 6be3352f52
commit afdf053288
4 changed files with 72 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import React from "react" import React from "react"
import { Link } from "react-router-dom"
import { import {
Row, Row,
Col, Col,
@ -156,6 +157,27 @@ class CreateFormDef extends React.PureComponent {
}) })
} }
handleSendOptinMail = record => {
this.props
.request(cs.Routes.SendSubscriberOptinMail, cs.MethodPost, {
id: record.id
})
.then(r => {
notification["success"]({
placement: cs.MsgPosition,
message: "Sent",
description: `Opt-in e-mail sentto ${record.email}`
})
})
.catch(e => {
notification["error"]({
placement: cs.MsgPosition,
message: "Error",
description: e.message
})
})
}
render() { render() {
const { formType, record } = this.props const { formType, record } = this.props
const { getFieldDecorator } = this.props.form const { getFieldDecorator } = this.props.form
@ -240,6 +262,24 @@ class CreateFormDef extends React.PureComponent {
))} ))}
</Select> </Select>
)} )}
{record.lists &&
record.lists.some(l => {
return (
l.subscription_status === cs.SubscriptionStatusUnConfirmed
)
}) && (
<Tooltip title="Send an opt-in e-mail to the subscriber to confirm subscriptions">
<Link
onClick={e => {
e.preventDefault()
this.handleSendOptinMail(record)
}}
to={`/`}
>
<Icon type="rocket" /> Send opt-in e-mail
</Link>
</Tooltip>
)}
</Form.Item> </Form.Item>
<Form.Item {...layout} label="Attributes" colon={false}> <Form.Item {...layout} label="Attributes" colon={false}>
<div> <div>

View File

@ -83,6 +83,7 @@ export const Routes = {
UpdateSubscriber: "/api/subscribers/:id", UpdateSubscriber: "/api/subscribers/:id",
DeleteSubscriber: "/api/subscribers/:id", DeleteSubscriber: "/api/subscribers/:id",
DeleteSubscribers: "/api/subscribers", DeleteSubscribers: "/api/subscribers",
SendSubscriberOptinMail: "/api/subscribers/:id/optin",
BlacklistSubscriber: "/api/subscribers/:id/blacklist", BlacklistSubscriber: "/api/subscribers/:id/blacklist",
BlacklistSubscribers: "/api/subscribers/blacklist", BlacklistSubscribers: "/api/subscribers/blacklist",
AddSubscriberToLists: "/api/subscribers/lists/:id", AddSubscriberToLists: "/api/subscribers/lists/:id",

View File

@ -44,6 +44,7 @@ func registerHandlers(e *echo.Echo) {
e.GET("/api/subscribers/:id/export", handleExportSubscriberData) e.GET("/api/subscribers/:id/export", handleExportSubscriberData)
e.POST("/api/subscribers", handleCreateSubscriber) e.POST("/api/subscribers", handleCreateSubscriber)
e.PUT("/api/subscribers/:id", handleUpdateSubscriber) e.PUT("/api/subscribers/:id", handleUpdateSubscriber)
e.POST("/api/subscribers/:id/optin", handleGetSubscriberSendOptin)
e.PUT("/api/subscribers/blacklist", handleBlacklistSubscribers) e.PUT("/api/subscribers/blacklist", handleBlacklistSubscribers)
e.PUT("/api/subscribers/:id/blacklist", handleBlacklistSubscribers) e.PUT("/api/subscribers/:id/blacklist", handleBlacklistSubscribers)
e.PUT("/api/subscribers/lists/:id", handleManageSubscriberLists) e.PUT("/api/subscribers/lists/:id", handleManageSubscriberLists)

View File

@ -232,6 +232,36 @@ func handleUpdateSubscriber(c echo.Context) error {
return handleGetSubscriber(c) return handleGetSubscriber(c)
} }
// handleGetSubscriberSendOptin sends an optin confirmation e-mail to a subscriber.
func handleGetSubscriberSendOptin(c echo.Context) error {
var (
app = c.Get("app").(*App)
id, _ = strconv.Atoi(c.Param("id"))
out models.Subscribers
)
if id < 1 {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid subscriber ID.")
}
// Fetch the subscriber.
err := app.Queries.GetSubscriber.Select(&out, id, nil)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError,
fmt.Sprintf("Error fetching subscriber: %s", pqErrMsg(err)))
}
if len(out) == 0 {
return echo.NewHTTPError(http.StatusBadRequest, "Subscriber not found.")
}
if err := sendOptinConfirmation(out[0], nil, app); err != nil {
return echo.NewHTTPError(http.StatusBadRequest,
"Error sending opt-in e-mail.")
}
return c.JSON(http.StatusOK, okResp{true})
}
// handleBlacklistSubscribers handles the blacklisting of one or more subscribers. // handleBlacklistSubscribers handles the blacklisting of one or more subscribers.
// It takes either an ID in the URI, or a list of IDs in the request body. // It takes either an ID in the URI, or a list of IDs in the request body.
func handleBlacklistSubscribers(c echo.Context) error { func handleBlacklistSubscribers(c echo.Context) error {