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.CREATED_AT]: number;
|
||||
[EmailTemplateInputDataFields.TEMPLATE]: string;
|
||||
[EmailTemplateInputDataFields.DESIGN]: string;
|
||||
}
|
||||
|
||||
interface UpdateEmailTemplateInputPropTypes {
|
||||
|
@ -102,20 +103,17 @@ const UpdateEmailTemplate = ({
|
|||
const [isDynamicVariableInfoOpen, setIsDynamicVariableInfoOpen] =
|
||||
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 = () => {
|
||||
// editor is ready
|
||||
console.log('onReady');
|
||||
if (selectedTemplate) {
|
||||
const { template } = selectedTemplate;
|
||||
console.log('incoming template ==>> ', template);
|
||||
const { design } = selectedTemplate;
|
||||
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 = () => {
|
||||
return (
|
||||
!loading &&
|
||||
emailEditorRef?.current &&
|
||||
templateData[EmailTemplateInputDataFields.EVENT_NAME].length > 0 &&
|
||||
templateData[EmailTemplateInputDataFields.SUBJECT].length > 0 &&
|
||||
validator[EmailTemplateInputDataFields.SUBJECT]
|
||||
|
@ -145,7 +142,6 @@ const UpdateEmailTemplate = ({
|
|||
// @ts-ignore
|
||||
return await emailEditorRef.current.editor.exportHtml(async (data) => {
|
||||
const { design, html } = data;
|
||||
console.log('design ==>> ', design);
|
||||
if (!html || !design) {
|
||||
setLoading(false);
|
||||
return;
|
||||
|
@ -156,6 +152,7 @@ const UpdateEmailTemplate = ({
|
|||
[EmailTemplateInputDataFields.SUBJECT]:
|
||||
templateData[EmailTemplateInputDataFields.SUBJECT],
|
||||
[EmailTemplateInputDataFields.TEMPLATE]: html.trim(),
|
||||
[EmailTemplateInputDataFields.DESIGN]: JSON.stringify(design),
|
||||
};
|
||||
let res: any = {};
|
||||
if (
|
||||
|
@ -217,7 +214,7 @@ const UpdateEmailTemplate = ({
|
|||
selectedTemplate &&
|
||||
Object.keys(selectedTemplate || {}).length
|
||||
) {
|
||||
const { id, created_at, template, ...rest } = selectedTemplate;
|
||||
const { id, created_at, template, design, ...rest } = selectedTemplate;
|
||||
setTemplateData(rest);
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
@ -419,11 +416,7 @@ const UpdateEmailTemplate = ({
|
|||
>
|
||||
Template Body
|
||||
</Flex>
|
||||
<EmailEditor
|
||||
ref={emailEditorRef}
|
||||
onLoad={onLoad}
|
||||
onReady={onReady}
|
||||
/>
|
||||
<EmailEditor ref={emailEditorRef} onReady={onReady} />
|
||||
</Flex>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
|
|
|
@ -168,6 +168,7 @@ export enum EmailTemplateInputDataFields {
|
|||
SUBJECT = 'subject',
|
||||
CREATED_AT = 'created_at',
|
||||
TEMPLATE = 'template',
|
||||
DESIGN = 'design',
|
||||
}
|
||||
|
||||
export enum WebhookInputHeaderFields {
|
||||
|
|
|
@ -132,6 +132,7 @@ export const EmailTemplatesQuery = `
|
|||
subject
|
||||
created_at
|
||||
template
|
||||
design
|
||||
}
|
||||
pagination {
|
||||
limit
|
||||
|
|
|
@ -58,6 +58,7 @@ interface EmailTemplateDataType {
|
|||
[EmailTemplateInputDataFields.SUBJECT]: string;
|
||||
[EmailTemplateInputDataFields.CREATED_AT]: number;
|
||||
[EmailTemplateInputDataFields.TEMPLATE]: string;
|
||||
[EmailTemplateInputDataFields.DESIGN]: string;
|
||||
}
|
||||
|
||||
const EmailTemplates = () => {
|
||||
|
|
|
@ -14,6 +14,7 @@ type EmailTemplate struct {
|
|||
EventName string `gorm:"unique" json:"event_name" bson:"event_name" cql:"event_name"`
|
||||
Subject string `gorm:"type:text" json:"subject" bson:"subject" cql:"subject"`
|
||||
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"`
|
||||
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
|
||||
}
|
||||
|
@ -29,6 +30,7 @@ func (e *EmailTemplate) AsAPIEmailTemplate() *model.EmailTemplate {
|
|||
EventName: e.EventName,
|
||||
Subject: e.Subject,
|
||||
Template: e.Template,
|
||||
Design: e.Design,
|
||||
CreatedAt: refs.NewInt64Ref(e.CreatedAt),
|
||||
UpdatedAt: refs.NewInt64Ref(e.UpdatedAt),
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ type ComplexityRoot struct {
|
|||
|
||||
EmailTemplate struct {
|
||||
CreatedAt func(childComplexity int) int
|
||||
Design func(childComplexity int) int
|
||||
EventName func(childComplexity int) int
|
||||
ID 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
|
||||
|
||||
case "EmailTemplate.design":
|
||||
if e.complexity.EmailTemplate.Design == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.EmailTemplate.Design(childComplexity), true
|
||||
|
||||
case "EmailTemplate.event_name":
|
||||
if e.complexity.EmailTemplate.EventName == nil {
|
||||
break
|
||||
|
@ -2059,6 +2067,7 @@ type EmailTemplate {
|
|||
id: ID!
|
||||
event_name: String!
|
||||
template: String!
|
||||
design: String!
|
||||
subject: String!
|
||||
created_at: Int64
|
||||
updated_at: Int64
|
||||
|
@ -2282,6 +2291,7 @@ input AddEmailTemplateRequest {
|
|||
event_name: String!
|
||||
subject: String!
|
||||
template: String!
|
||||
design: String!
|
||||
}
|
||||
|
||||
input UpdateEmailTemplateRequest {
|
||||
|
@ -2289,6 +2299,7 @@ input UpdateEmailTemplateRequest {
|
|||
event_name: String
|
||||
template: String
|
||||
subject: String
|
||||
design: String
|
||||
}
|
||||
|
||||
input DeleteEmailTemplateRequest {
|
||||
|
@ -3270,6 +3281,41 @@ func (ec *executionContext) _EmailTemplate_template(ctx context.Context, field g
|
|||
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) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -10521,6 +10567,14 @@ func (ec *executionContext) unmarshalInputAddEmailTemplateRequest(ctx context.Co
|
|||
if err != nil {
|
||||
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 {
|
||||
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 {
|
||||
invalids++
|
||||
}
|
||||
case "design":
|
||||
out.Values[i] = ec._EmailTemplate_design(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "subject":
|
||||
out.Values[i] = ec._EmailTemplate_subject(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
|
|
|
@ -6,6 +6,7 @@ type AddEmailTemplateRequest struct {
|
|||
EventName string `json:"event_name"`
|
||||
Subject string `json:"subject"`
|
||||
Template string `json:"template"`
|
||||
Design string `json:"design"`
|
||||
}
|
||||
|
||||
type AddWebhookRequest struct {
|
||||
|
@ -45,6 +46,7 @@ type EmailTemplate struct {
|
|||
ID string `json:"id"`
|
||||
EventName string `json:"event_name"`
|
||||
Template string `json:"template"`
|
||||
Design string `json:"design"`
|
||||
Subject string `json:"subject"`
|
||||
CreatedAt *int64 `json:"created_at"`
|
||||
UpdatedAt *int64 `json:"updated_at"`
|
||||
|
@ -252,6 +254,7 @@ type UpdateEmailTemplateRequest struct {
|
|||
EventName *string `json:"event_name"`
|
||||
Template *string `json:"template"`
|
||||
Subject *string `json:"subject"`
|
||||
Design *string `json:"design"`
|
||||
}
|
||||
|
||||
type UpdateEnvInput struct {
|
||||
|
|
|
@ -194,6 +194,7 @@ type EmailTemplate {
|
|||
id: ID!
|
||||
event_name: String!
|
||||
template: String!
|
||||
design: String!
|
||||
subject: String!
|
||||
created_at: Int64
|
||||
updated_at: Int64
|
||||
|
@ -417,6 +418,7 @@ input AddEmailTemplateRequest {
|
|||
event_name: String!
|
||||
subject: String!
|
||||
template: String!
|
||||
design: String!
|
||||
}
|
||||
|
||||
input UpdateEmailTemplateRequest {
|
||||
|
@ -424,6 +426,7 @@ input UpdateEmailTemplateRequest {
|
|||
event_name: String
|
||||
template: String
|
||||
subject: String
|
||||
design: String
|
||||
}
|
||||
|
||||
input DeleteEmailTemplateRequest {
|
||||
|
|
|
@ -40,10 +40,15 @@ func AddEmailTemplateResolver(ctx context.Context, params model.AddEmailTemplate
|
|||
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{
|
||||
EventName: params.EventName,
|
||||
Template: params.Template,
|
||||
Subject: params.Subject,
|
||||
Design: params.Design,
|
||||
})
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue
Block a user