fix: add design to email template
This commit is contained in:
parent
6c29149fbe
commit
d7f5f563cc
|
@ -48,6 +48,7 @@ interface selectedEmailTemplateDataTypes {
|
||||||
[EmailTemplateInputDataFields.SUBJECT]: string;
|
[EmailTemplateInputDataFields.SUBJECT]: string;
|
||||||
[EmailTemplateInputDataFields.CREATED_AT]: number;
|
[EmailTemplateInputDataFields.CREATED_AT]: number;
|
||||||
[EmailTemplateInputDataFields.TEMPLATE]: string;
|
[EmailTemplateInputDataFields.TEMPLATE]: string;
|
||||||
|
[EmailTemplateInputDataFields.DESIGN]: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UpdateEmailTemplateInputPropTypes {
|
interface UpdateEmailTemplateInputPropTypes {
|
||||||
|
@ -102,20 +103,17 @@ const UpdateEmailTemplate = ({
|
||||||
const [isDynamicVariableInfoOpen, setIsDynamicVariableInfoOpen] =
|
const [isDynamicVariableInfoOpen, setIsDynamicVariableInfoOpen] =
|
||||||
useState<boolean>(false);
|
useState<boolean>(false);
|
||||||
|
|
||||||
const onLoad = () => {
|
|
||||||
// editor instance is created
|
|
||||||
// you can load your template here;
|
|
||||||
// const templateJson = {};
|
|
||||||
// emailEditorRef.current.editor.loadDesign(templateJson);
|
|
||||||
console.log('onLoad');
|
|
||||||
};
|
|
||||||
|
|
||||||
const onReady = () => {
|
const onReady = () => {
|
||||||
// editor is ready
|
|
||||||
console.log('onReady');
|
|
||||||
if (selectedTemplate) {
|
if (selectedTemplate) {
|
||||||
const { template } = selectedTemplate;
|
const { design } = selectedTemplate;
|
||||||
console.log('incoming template ==>> ', template);
|
try {
|
||||||
|
const designData = JSON.parse(design);
|
||||||
|
// @ts-ignore
|
||||||
|
emailEditorRef.current.editor.loadDesign(designData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,7 +130,6 @@ const UpdateEmailTemplate = ({
|
||||||
const validateData = () => {
|
const validateData = () => {
|
||||||
return (
|
return (
|
||||||
!loading &&
|
!loading &&
|
||||||
emailEditorRef?.current &&
|
|
||||||
templateData[EmailTemplateInputDataFields.EVENT_NAME].length > 0 &&
|
templateData[EmailTemplateInputDataFields.EVENT_NAME].length > 0 &&
|
||||||
templateData[EmailTemplateInputDataFields.SUBJECT].length > 0 &&
|
templateData[EmailTemplateInputDataFields.SUBJECT].length > 0 &&
|
||||||
validator[EmailTemplateInputDataFields.SUBJECT]
|
validator[EmailTemplateInputDataFields.SUBJECT]
|
||||||
|
@ -145,7 +142,6 @@ const UpdateEmailTemplate = ({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return await emailEditorRef.current.editor.exportHtml(async (data) => {
|
return await emailEditorRef.current.editor.exportHtml(async (data) => {
|
||||||
const { design, html } = data;
|
const { design, html } = data;
|
||||||
console.log('design ==>> ', design);
|
|
||||||
if (!html || !design) {
|
if (!html || !design) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
|
@ -156,6 +152,7 @@ const UpdateEmailTemplate = ({
|
||||||
[EmailTemplateInputDataFields.SUBJECT]:
|
[EmailTemplateInputDataFields.SUBJECT]:
|
||||||
templateData[EmailTemplateInputDataFields.SUBJECT],
|
templateData[EmailTemplateInputDataFields.SUBJECT],
|
||||||
[EmailTemplateInputDataFields.TEMPLATE]: html.trim(),
|
[EmailTemplateInputDataFields.TEMPLATE]: html.trim(),
|
||||||
|
[EmailTemplateInputDataFields.DESIGN]: JSON.stringify(design),
|
||||||
};
|
};
|
||||||
let res: any = {};
|
let res: any = {};
|
||||||
if (
|
if (
|
||||||
|
@ -217,7 +214,7 @@ const UpdateEmailTemplate = ({
|
||||||
selectedTemplate &&
|
selectedTemplate &&
|
||||||
Object.keys(selectedTemplate || {}).length
|
Object.keys(selectedTemplate || {}).length
|
||||||
) {
|
) {
|
||||||
const { id, created_at, template, ...rest } = selectedTemplate;
|
const { id, created_at, template, design, ...rest } = selectedTemplate;
|
||||||
setTemplateData(rest);
|
setTemplateData(rest);
|
||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
@ -419,11 +416,7 @@ const UpdateEmailTemplate = ({
|
||||||
>
|
>
|
||||||
Template Body
|
Template Body
|
||||||
</Flex>
|
</Flex>
|
||||||
<EmailEditor
|
<EmailEditor ref={emailEditorRef} onReady={onReady} />
|
||||||
ref={emailEditorRef}
|
|
||||||
onLoad={onLoad}
|
|
||||||
onReady={onReady}
|
|
||||||
/>
|
|
||||||
</Flex>
|
</Flex>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|
|
@ -168,6 +168,7 @@ export enum EmailTemplateInputDataFields {
|
||||||
SUBJECT = 'subject',
|
SUBJECT = 'subject',
|
||||||
CREATED_AT = 'created_at',
|
CREATED_AT = 'created_at',
|
||||||
TEMPLATE = 'template',
|
TEMPLATE = 'template',
|
||||||
|
DESIGN = 'design',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum WebhookInputHeaderFields {
|
export enum WebhookInputHeaderFields {
|
||||||
|
|
|
@ -132,6 +132,7 @@ export const EmailTemplatesQuery = `
|
||||||
subject
|
subject
|
||||||
created_at
|
created_at
|
||||||
template
|
template
|
||||||
|
design
|
||||||
}
|
}
|
||||||
pagination {
|
pagination {
|
||||||
limit
|
limit
|
||||||
|
|
|
@ -58,6 +58,7 @@ interface EmailTemplateDataType {
|
||||||
[EmailTemplateInputDataFields.SUBJECT]: string;
|
[EmailTemplateInputDataFields.SUBJECT]: string;
|
||||||
[EmailTemplateInputDataFields.CREATED_AT]: number;
|
[EmailTemplateInputDataFields.CREATED_AT]: number;
|
||||||
[EmailTemplateInputDataFields.TEMPLATE]: string;
|
[EmailTemplateInputDataFields.TEMPLATE]: string;
|
||||||
|
[EmailTemplateInputDataFields.DESIGN]: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EmailTemplates = () => {
|
const EmailTemplates = () => {
|
||||||
|
|
|
@ -14,6 +14,7 @@ type EmailTemplate struct {
|
||||||
EventName string `gorm:"unique" json:"event_name" bson:"event_name" cql:"event_name"`
|
EventName string `gorm:"unique" json:"event_name" bson:"event_name" cql:"event_name"`
|
||||||
Subject string `gorm:"type:text" json:"subject" bson:"subject" cql:"subject"`
|
Subject string `gorm:"type:text" json:"subject" bson:"subject" cql:"subject"`
|
||||||
Template string `gorm:"type:text" json:"template" bson:"template" cql:"template"`
|
Template string `gorm:"type:text" json:"template" bson:"template" cql:"template"`
|
||||||
|
Design string `gorm:"type:text" json:"design" bson:"design" cql:"design"`
|
||||||
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at"`
|
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at"`
|
||||||
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
|
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
|
||||||
}
|
}
|
||||||
|
@ -29,6 +30,7 @@ func (e *EmailTemplate) AsAPIEmailTemplate() *model.EmailTemplate {
|
||||||
EventName: e.EventName,
|
EventName: e.EventName,
|
||||||
Subject: e.Subject,
|
Subject: e.Subject,
|
||||||
Template: e.Template,
|
Template: e.Template,
|
||||||
|
Design: e.Design,
|
||||||
CreatedAt: refs.NewInt64Ref(e.CreatedAt),
|
CreatedAt: refs.NewInt64Ref(e.CreatedAt),
|
||||||
UpdatedAt: refs.NewInt64Ref(e.UpdatedAt),
|
UpdatedAt: refs.NewInt64Ref(e.UpdatedAt),
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ type ComplexityRoot struct {
|
||||||
|
|
||||||
EmailTemplate struct {
|
EmailTemplate struct {
|
||||||
CreatedAt func(childComplexity int) int
|
CreatedAt func(childComplexity int) int
|
||||||
|
Design func(childComplexity int) int
|
||||||
EventName func(childComplexity int) int
|
EventName func(childComplexity int) int
|
||||||
ID func(childComplexity int) int
|
ID func(childComplexity int) int
|
||||||
Subject func(childComplexity int) int
|
Subject func(childComplexity int) int
|
||||||
|
@ -406,6 +407,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||||
|
|
||||||
return e.complexity.EmailTemplate.CreatedAt(childComplexity), true
|
return e.complexity.EmailTemplate.CreatedAt(childComplexity), true
|
||||||
|
|
||||||
|
case "EmailTemplate.design":
|
||||||
|
if e.complexity.EmailTemplate.Design == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.complexity.EmailTemplate.Design(childComplexity), true
|
||||||
|
|
||||||
case "EmailTemplate.event_name":
|
case "EmailTemplate.event_name":
|
||||||
if e.complexity.EmailTemplate.EventName == nil {
|
if e.complexity.EmailTemplate.EventName == nil {
|
||||||
break
|
break
|
||||||
|
@ -2059,6 +2067,7 @@ type EmailTemplate {
|
||||||
id: ID!
|
id: ID!
|
||||||
event_name: String!
|
event_name: String!
|
||||||
template: String!
|
template: String!
|
||||||
|
design: String!
|
||||||
subject: String!
|
subject: String!
|
||||||
created_at: Int64
|
created_at: Int64
|
||||||
updated_at: Int64
|
updated_at: Int64
|
||||||
|
@ -2282,6 +2291,7 @@ input AddEmailTemplateRequest {
|
||||||
event_name: String!
|
event_name: String!
|
||||||
subject: String!
|
subject: String!
|
||||||
template: String!
|
template: String!
|
||||||
|
design: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
input UpdateEmailTemplateRequest {
|
input UpdateEmailTemplateRequest {
|
||||||
|
@ -2289,6 +2299,7 @@ input UpdateEmailTemplateRequest {
|
||||||
event_name: String
|
event_name: String
|
||||||
template: String
|
template: String
|
||||||
subject: String
|
subject: String
|
||||||
|
design: String
|
||||||
}
|
}
|
||||||
|
|
||||||
input DeleteEmailTemplateRequest {
|
input DeleteEmailTemplateRequest {
|
||||||
|
@ -3270,6 +3281,41 @@ func (ec *executionContext) _EmailTemplate_template(ctx context.Context, field g
|
||||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) _EmailTemplate_design(ctx context.Context, field graphql.CollectedField, obj *model.EmailTemplate) (ret graphql.Marshaler) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
ret = graphql.Null
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
fc := &graphql.FieldContext{
|
||||||
|
Object: "EmailTemplate",
|
||||||
|
Field: field,
|
||||||
|
Args: nil,
|
||||||
|
IsMethod: false,
|
||||||
|
IsResolver: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = graphql.WithFieldContext(ctx, fc)
|
||||||
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
|
ctx = rctx // use context from middleware stack in children
|
||||||
|
return obj.Design, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
if resTmp == nil {
|
||||||
|
if !graphql.HasFieldError(ctx, fc) {
|
||||||
|
ec.Errorf(ctx, "must not be null")
|
||||||
|
}
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
res := resTmp.(string)
|
||||||
|
fc.Result = res
|
||||||
|
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||||
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _EmailTemplate_subject(ctx context.Context, field graphql.CollectedField, obj *model.EmailTemplate) (ret graphql.Marshaler) {
|
func (ec *executionContext) _EmailTemplate_subject(ctx context.Context, field graphql.CollectedField, obj *model.EmailTemplate) (ret graphql.Marshaler) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
|
@ -10521,6 +10567,14 @@ func (ec *executionContext) unmarshalInputAddEmailTemplateRequest(ctx context.Co
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return it, err
|
return it, err
|
||||||
}
|
}
|
||||||
|
case "design":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("design"))
|
||||||
|
it.Design, err = ec.unmarshalNString2string(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11331,6 +11385,14 @@ func (ec *executionContext) unmarshalInputUpdateEmailTemplateRequest(ctx context
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return it, err
|
return it, err
|
||||||
}
|
}
|
||||||
|
case "design":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("design"))
|
||||||
|
it.Design, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12162,6 +12224,11 @@ func (ec *executionContext) _EmailTemplate(ctx context.Context, sel ast.Selectio
|
||||||
if out.Values[i] == graphql.Null {
|
if out.Values[i] == graphql.Null {
|
||||||
invalids++
|
invalids++
|
||||||
}
|
}
|
||||||
|
case "design":
|
||||||
|
out.Values[i] = ec._EmailTemplate_design(ctx, field, obj)
|
||||||
|
if out.Values[i] == graphql.Null {
|
||||||
|
invalids++
|
||||||
|
}
|
||||||
case "subject":
|
case "subject":
|
||||||
out.Values[i] = ec._EmailTemplate_subject(ctx, field, obj)
|
out.Values[i] = ec._EmailTemplate_subject(ctx, field, obj)
|
||||||
if out.Values[i] == graphql.Null {
|
if out.Values[i] == graphql.Null {
|
||||||
|
|
|
@ -6,6 +6,7 @@ type AddEmailTemplateRequest struct {
|
||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
Template string `json:"template"`
|
Template string `json:"template"`
|
||||||
|
Design string `json:"design"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddWebhookRequest struct {
|
type AddWebhookRequest struct {
|
||||||
|
@ -45,6 +46,7 @@ type EmailTemplate struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
Template string `json:"template"`
|
Template string `json:"template"`
|
||||||
|
Design string `json:"design"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
CreatedAt *int64 `json:"created_at"`
|
CreatedAt *int64 `json:"created_at"`
|
||||||
UpdatedAt *int64 `json:"updated_at"`
|
UpdatedAt *int64 `json:"updated_at"`
|
||||||
|
@ -252,6 +254,7 @@ type UpdateEmailTemplateRequest struct {
|
||||||
EventName *string `json:"event_name"`
|
EventName *string `json:"event_name"`
|
||||||
Template *string `json:"template"`
|
Template *string `json:"template"`
|
||||||
Subject *string `json:"subject"`
|
Subject *string `json:"subject"`
|
||||||
|
Design *string `json:"design"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateEnvInput struct {
|
type UpdateEnvInput struct {
|
||||||
|
|
|
@ -194,6 +194,7 @@ type EmailTemplate {
|
||||||
id: ID!
|
id: ID!
|
||||||
event_name: String!
|
event_name: String!
|
||||||
template: String!
|
template: String!
|
||||||
|
design: String!
|
||||||
subject: String!
|
subject: String!
|
||||||
created_at: Int64
|
created_at: Int64
|
||||||
updated_at: Int64
|
updated_at: Int64
|
||||||
|
@ -417,6 +418,7 @@ input AddEmailTemplateRequest {
|
||||||
event_name: String!
|
event_name: String!
|
||||||
subject: String!
|
subject: String!
|
||||||
template: String!
|
template: String!
|
||||||
|
design: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
input UpdateEmailTemplateRequest {
|
input UpdateEmailTemplateRequest {
|
||||||
|
@ -424,6 +426,7 @@ input UpdateEmailTemplateRequest {
|
||||||
event_name: String
|
event_name: String
|
||||||
template: String
|
template: String
|
||||||
subject: String
|
subject: String
|
||||||
|
design: String
|
||||||
}
|
}
|
||||||
|
|
||||||
input DeleteEmailTemplateRequest {
|
input DeleteEmailTemplateRequest {
|
||||||
|
|
|
@ -40,10 +40,15 @@ func AddEmailTemplateResolver(ctx context.Context, params model.AddEmailTemplate
|
||||||
return nil, fmt.Errorf("empty template not allowed")
|
return nil, fmt.Errorf("empty template not allowed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(params.Design) == "" {
|
||||||
|
return nil, fmt.Errorf("empty design not allowed")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = db.Provider.AddEmailTemplate(ctx, models.EmailTemplate{
|
_, err = db.Provider.AddEmailTemplate(ctx, models.EmailTemplate{
|
||||||
EventName: params.EventName,
|
EventName: params.EventName,
|
||||||
Template: params.Template,
|
Template: params.Template,
|
||||||
Subject: params.Subject,
|
Subject: params.Subject,
|
||||||
|
Design: params.Design,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to add email template: ", err)
|
log.Debug("Failed to add email template: ", err)
|
||||||
|
|
|
@ -65,6 +65,14 @@ func UpdateEmailTemplateResolver(ctx context.Context, params model.UpdateEmailTe
|
||||||
emailTemplateDetails.Template = refs.StringValue(params.Template)
|
emailTemplateDetails.Template = refs.StringValue(params.Template)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if params.Design != nil && emailTemplateDetails.Design != refs.StringValue(params.Design) {
|
||||||
|
if strings.TrimSpace(refs.StringValue(params.Design)) == "" {
|
||||||
|
log.Debug("empty design not allowed")
|
||||||
|
return nil, fmt.Errorf("empty design not allowed")
|
||||||
|
}
|
||||||
|
emailTemplateDetails.Design = refs.StringValue(params.Design)
|
||||||
|
}
|
||||||
|
|
||||||
_, err = db.Provider.UpdateEmailTemplate(ctx, emailTemplateDetails)
|
_, err = db.Provider.UpdateEmailTemplate(ctx, emailTemplateDetails)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user