Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

feat(tenant): add description template field to tenant settings

Jeffrey van den Hondela746f1a8c780
diff --git a/app/actions/tenant.go b/app/actions/tenant.go
index 7c957eb1a..4c41abe8e 100644
--- a/app/actions/tenant.go
+++ b/app/actions/tenant.go
@@ -190,13 +190,14 @@ func (action *ResendSignUpEmail) GetKind() enum.EmailVerificationKind {
// UpdateTenantSettings is the input model used to update tenant settings
type UpdateTenantSettings struct {
- Logo *dto.ImageUpload `json:"logo"`
- Title string `json:"title"`
- Invitation string `json:"invitation"`
- WelcomeMessage string `json:"welcomeMessage"`
- WelcomeHeader string `json:"welcomeHeader"`
- Locale string `json:"locale"`
- CNAME string `json:"cname" format:"lower"`
+ Logo *dto.ImageUpload `json:"logo"`
+ Title string `json:"title"`
+ Invitation string `json:"invitation"`
+ WelcomeMessage string `json:"welcomeMessage"`
+ WelcomeHeader string `json:"welcomeHeader"`
+ DescriptionTemplate string `json:"descriptionTemplate"`
+ Locale string `json:"locale"`
+ CNAME string `json:"cname" format:"lower"`
}
func NewUpdateTenantSettings() *UpdateTenantSettings {
@@ -247,6 +248,10 @@ func (action *UpdateTenantSettings) Validate(ctx context.Context, user *entity.U
result.AddFieldFailure("welcomeHeader", "Welcome Header must have less than 100 characters.")
}
+ if len(action.DescriptionTemplate) > 2000 {
+ result.AddFieldFailure("descriptionTemplate", "Idea Template must have less than 2000 characters.")
+ }
+
if !i18n.IsValidLocale(action.Locale) {
result.AddFieldFailure("locale", "Locale is invalid.")
}
diff --git a/app/handlers/admin.go b/app/handlers/admin.go
index ad3182c2b..6ffd5462e 100644
--- a/app/handlers/admin.go
+++ b/app/handlers/admin.go
@@ -52,13 +52,14 @@ func UpdateSettings() web.HandlerFunc {
Folder: "logos",
},
&cmd.UpdateTenantSettings{
- Logo: action.Logo,
- Title: action.Title,
- Invitation: action.Invitation,
- WelcomeMessage: action.WelcomeMessage,
- WelcomeHeader: action.WelcomeHeader,
- CNAME: action.CNAME,
- Locale: action.Locale,
+ Logo: action.Logo,
+ Title: action.Title,
+ Invitation: action.Invitation,
+ WelcomeMessage: action.WelcomeMessage,
+ WelcomeHeader: action.WelcomeHeader,
+ DescriptionTemplate: action.DescriptionTemplate,
+ CNAME: action.CNAME,
+ Locale: action.Locale,
},
); err != nil {
return c.Failure(err)
diff --git a/app/models/cmd/tenant.go b/app/models/cmd/tenant.go
index 0b18f211f..6fe822bc2 100644
--- a/app/models/cmd/tenant.go
+++ b/app/models/cmd/tenant.go
@@ -27,13 +27,14 @@ type UpdateTenantEmailAuthAllowedSettings struct {
}
type UpdateTenantSettings struct {
- Logo *dto.ImageUpload
- Title string
- Invitation string
- WelcomeMessage string
- WelcomeHeader string
- CNAME string
- Locale string
+ Logo *dto.ImageUpload
+ Title string
+ Invitation string
+ WelcomeMessage string
+ WelcomeHeader string
+ DescriptionTemplate string
+ CNAME string
+ Locale string
}
type UpdateTenantAdvancedSettings struct {
diff --git a/app/models/entity/tenant.go b/app/models/entity/tenant.go
index e1d936b12..badaf8321 100644
--- a/app/models/entity/tenant.go
+++ b/app/models/entity/tenant.go
@@ -12,6 +12,7 @@ type Tenant struct {
Invitation string `json:"invitation"`
WelcomeMessage string `json:"welcomeMessage"`
WelcomeHeader string `json:"welcomeHeader"`
+ DescriptionTemplate string `json:"descriptionTemplate"`
CNAME string `json:"cname"`
Status enum.TenantStatus `json:"status"`
Locale string `json:"locale"`
diff --git a/app/services/sqlstore/dbEntities/tenant.go b/app/services/sqlstore/dbEntities/tenant.go
index bdd710e90..b0fd2d65a 100644
--- a/app/services/sqlstore/dbEntities/tenant.go
+++ b/app/services/sqlstore/dbEntities/tenant.go
@@ -14,6 +14,7 @@ type Tenant struct {
Invitation string `db:"invitation"`
WelcomeMessage string `db:"welcome_message"`
WelcomeHeader string `db:"welcome_header"`
+ DescriptionTemplate string `db:"description_template"`
Status int `db:"status"`
Locale string `db:"locale"`
IsPrivate bool `db:"is_private"`
@@ -48,6 +49,7 @@ func (t *Tenant) ToModel() *entity.Tenant {
Invitation: t.Invitation,
WelcomeMessage: t.WelcomeMessage,
WelcomeHeader: t.WelcomeHeader,
+ DescriptionTemplate: t.DescriptionTemplate,
Status: enum.TenantStatus(t.Status),
Locale: t.Locale,
IsPrivate: t.IsPrivate,
diff --git a/app/services/sqlstore/postgres/tenant.go b/app/services/sqlstore/postgres/tenant.go
index 0051275b3..479bba459 100644
--- a/app/services/sqlstore/postgres/tenant.go
+++ b/app/services/sqlstore/postgres/tenant.go
@@ -80,8 +80,8 @@ func updateTenantSettings(ctx context.Context, c *cmd.UpdateTenantSettings) erro
c.Logo.BlobKey = ""
}
- query := "UPDATE tenants SET name = $1, invitation = $2, welcome_message = $3, welcome_header = $4, cname = $5, logo_bkey = $6, locale = $7 WHERE id = $8"
- _, err := trx.Execute(query, c.Title, c.Invitation, c.WelcomeMessage, c.WelcomeHeader, c.CNAME, c.Logo.BlobKey, c.Locale, tenant.ID)
+ query := "UPDATE tenants SET name = $1, invitation = $2, welcome_message = $3, welcome_header = $4, description_template = $5, cname = $6, logo_bkey = $7, locale = $8 WHERE id = $9"
+ _, err := trx.Execute(query, c.Title, c.Invitation, c.WelcomeMessage, c.WelcomeHeader, c.DescriptionTemplate, c.CNAME, c.Logo.BlobKey, c.Locale, tenant.ID)
if err != nil {
return errors.Wrap(err, "failed update tenant settings")
}
@@ -91,6 +91,7 @@ func updateTenantSettings(ctx context.Context, c *cmd.UpdateTenantSettings) erro
tenant.CNAME = c.CNAME
tenant.WelcomeMessage = c.WelcomeMessage
tenant.WelcomeHeader = c.WelcomeHeader
+ tenant.DescriptionTemplate = c.DescriptionTemplate
return nil
})
@@ -259,7 +260,7 @@ func getFirstTenant(ctx context.Context, q *query.GetFirstTenant) error {
tenant := dbEntities.Tenant{}
err := trx.Get(&tenant, `
- SELECT t.id, t.name, t.subdomain, t.cname, t.invitation, t.locale, t.welcome_message, t.welcome_header, t.status, t.is_private, t.logo_bkey, t.custom_css, t.allowed_schemes, t.is_email_auth_allowed, t.is_feed_enabled, t.is_moderation_enabled, t.prevent_indexing, t.is_pro,
+ SELECT t.id, t.name, t.subdomain, t.cname, t.invitation, t.locale, t.welcome_message, t.welcome_header, t.description_template, t.status, t.is_private, t.logo_bkey, t.custom_css, t.allowed_schemes, t.is_email_auth_allowed, t.is_feed_enabled, t.is_moderation_enabled, t.prevent_indexing, t.is_pro,
(b.paddle_subscription_id IS NOT NULL AND b.stripe_subscription_id IS NULL) AS has_paddle_subscription
FROM tenants t
LEFT JOIN tenants_billing b ON b.tenant_id = t.id
@@ -279,7 +280,7 @@ func getTenantByDomain(ctx context.Context, q *query.GetTenantByDomain) error {
tenant := dbEntities.Tenant{}
err := trx.Get(&tenant, `
- SELECT t.id, t.name, t.subdomain, t.cname, t.invitation, t.locale, t.welcome_message, t.welcome_header, t.status, t.is_private, t.logo_bkey, t.custom_css, t.allowed_schemes, t.is_email_auth_allowed, t.is_feed_enabled, t.is_moderation_enabled, t.prevent_indexing, t.is_pro,
+ SELECT t.id, t.name, t.subdomain, t.cname, t.invitation, t.locale, t.welcome_message, t.welcome_header, t.description_template, t.status, t.is_private, t.logo_bkey, t.custom_css, t.allowed_schemes, t.is_email_auth_allowed, t.is_feed_enabled, t.is_moderation_enabled, t.prevent_indexing, t.is_pro,
(b.paddle_subscription_id IS NOT NULL AND b.stripe_subscription_id IS NULL) AS has_paddle_subscription
FROM tenants t
LEFT JOIN tenants_billing b ON b.tenant_id = t.id
diff --git a/migrations/202606081200_add_tenant_description_template.sql b/migrations/202606081200_add_tenant_description_template.sql
new file mode 100644
index 000000000..817f10a2a
--- /dev/null
+++ b/migrations/202606081200_add_tenant_description_template.sql
@@ -0,0 +1 @@
+ALTER TABLE tenants ADD COLUMN description_template TEXT NOT NULL DEFAULT '';
diff --git a/public/models/identity.ts b/public/models/identity.ts
index 2281a76bd..8ba53f00e 100644
--- a/public/models/identity.ts
+++ b/public/models/identity.ts
@@ -7,6 +7,7 @@ export interface Tenant {
invitation: string
welcomeMessage: string
welcomeHeader: string
+ descriptionTemplate: string
status: TenantStatus
isPrivate: boolean
logoBlobKey: string
diff --git a/public/pages/Administration/pages/GeneralSettings.page.tsx b/public/pages/Administration/pages/GeneralSettings.page.tsx
index 1a44518fa..bb8931008 100644
--- a/public/pages/Administration/pages/GeneralSettings.page.tsx
+++ b/public/pages/Administration/pages/GeneralSettings.page.tsx
@@ -12,6 +12,7 @@ const GeneralSettingsPage = () => {
const [title, setTitle] = useState<string>(fider.session.tenant.name)
const [welcomeMessage, setWelcomeMessage] = useState<string>(fider.session.tenant.welcomeMessage)
const [welcomeHeader, setWelcomeHeader] = useState<string>(fider.session.tenant.welcomeHeader)
+ const [descriptionTemplate, setDescriptionTemplate] = useState<string>(fider.session.tenant.descriptionTemplate)
const [invitation, setInvitation] = useState<string>(fider.session.tenant.invitation)
const [logo, setLogo] = useState<ImageUpload | undefined>(undefined)
const [cname, setCNAME] = useState<string>(fider.session.tenant.cname)
@@ -19,7 +20,7 @@ const GeneralSettingsPage = () => {
const [error, setError] = useState<Failure | undefined>(undefined)
const handleSave = async (e: ButtonClickEvent) => {
- const result = await actions.updateTenantSettings({ title, cname, welcomeMessage, welcomeHeader, invitation, logo, locale })
+ const result = await actions.updateTenantSettings({ title, cname, welcomeMessage, welcomeHeader, descriptionTemplate, invitation, logo, locale })
if (result.ok) {
e.preventEnable()
location.href = `/`
@@ -76,6 +77,19 @@ const GeneralSettingsPage = () => {
</p>
</TextArea>
+ <TextArea
+ field="descriptionTemplate"
+ label="Idea Template"
+ value={descriptionTemplate}
+ disabled={!fider.session.user.isAdministrator}
+ onChange={setDescriptionTemplate}
+ >
+ <p className="text-muted">
+ Prefilled into the description box when someone shares a new idea, so visitors fill in a structured template instead of a blank field. Markdown is
+ supported. Leave empty to use the default template.
+ </p>
+ </TextArea>
+
<Input
field="invitation"
label="Invitation"
diff --git a/public/pages/Home/components/ShareFeedback.tsx b/public/pages/Home/components/ShareFeedback.tsx
index 84ae1d494..4e7eaa9ff 100644
--- a/public/pages/Home/components/ShareFeedback.tsx
+++ b/public/pages/Home/components/ShareFeedback.tsx
@@ -55,8 +55,13 @@ export const ShareFeedback: React.FC<ShareFeedbackProps> = (props) => {
}
const canEditTags = fider.settings.postWithTags && props.tags.length > 0
+
+ const descriptionTemplate = fider.session.tenant.descriptionTemplate || ""
+ const hasCachedDraft = getCachedDescription() !== ""
+ const prefillTemplate = !hasCachedDraft && descriptionTemplate !== ""
+
const [title, setTitle] = useState(getCachedTitle())
- const [description, setDescription] = useState(getCachedDescription())
+ const [description, setDescription] = useState(prefillTemplate ? descriptionTemplate : getCachedDescription())
const { attachments, handleImageUploaded, getImageSrc, clearAttachments } = useAttachments({
cacheKey: CACHE_KEYS.ATTACHMENT,
useLocalStorage: true,
@@ -66,7 +71,7 @@ export const ShareFeedback: React.FC<ShareFeedbackProps> = (props) => {
const [error, setError] = useState<Failure | undefined>(undefined)
const titleRef = useRef<HTMLInputElement>()
const editorRef = useRef<HTMLDivElement>(null)
- const [titleManuallyEdited, setTitleManuallyEdited] = useState(getTitleManuallyEditedValue())
+ const [titleManuallyEdited, setTitleManuallyEdited] = useState(prefillTemplate ? true : getTitleManuallyEditedValue())
const [isInitialMount, setIsInitialMount] = useState(true)
useEffect(() => {
diff --git a/public/services/actions/tenant.ts b/public/services/actions/tenant.ts
index 2ea49da70..b51d9d364 100644
--- a/public/services/actions/tenant.ts
+++ b/public/services/actions/tenant.ts
@@ -29,6 +29,7 @@ export interface UpdateTenantSettingsRequest {
invitation: string
welcomeMessage: string
welcomeHeader: string
+ descriptionTemplate: string
cname: string
locale: string
}