A platform for community discussion. Free, open, simple.
DEV: Convert feature topic modal to FormKit (#39690)
Derek Rushforthcc66a5e8a955
diff --git a/app/assets/stylesheets/common/components/_index.scss b/app/assets/stylesheets/common/components/_index.scssindex e1d87f32590..7174aee0e12 100644--- a/app/assets/stylesheets/common/components/_index.scss+++ b/app/assets/stylesheets/common/components/_index.scss@@ -29,6 +29,7 @@@import "d-combo-button";@import "drafts-dropdown-menu";@import "empty-states";+@import "feature-topic-modal";@import "file-size-input";@import "footer-nav";@import "form-template-field";diff --git a/app/assets/stylesheets/common/components/feature-topic-modal.scss b/app/assets/stylesheets/common/components/feature-topic-modal.scssnew file mode 100644index 00000000000..ea42f7544fd--- /dev/null+++ b/app/assets/stylesheets/common/components/feature-topic-modal.scss@@ -0,0 +1,17 @@+@use "lib/viewport";++.feature-section {+ &__description {+ width: 100%;+ }++ &__pin-message {+ margin-bottom: var(--space-1);++ .d-icon {+ @include viewport.until(sm) {+ display: none;+ }+ }+ }+}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex d7cc72ef993..d4468491816 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4289,6 +4289,7 @@ en:unpin: "Remove this topic from the top of the %{categoryLink} category."unpin_until: "Remove this topic from the top of the %{categoryLink} category or wait until <strong>%{until}</strong>."pin_note: "Users can unpin the topic individually for themselves."+ pin_until: "Pin until"pin_validation: "A date is required to pin this topic."not_pinned: "There are no topics pinned in %{categoryLink}."already_pinned:diff --git a/frontend/discourse/app/components/modal/feature-topic.gjs b/frontend/discourse/app/components/modal/feature-topic.gjsindex b8f55b11d1c..21b6a96101f 100644--- a/frontend/discourse/app/components/modal/feature-topic.gjs+++ b/frontend/discourse/app/components/modal/feature-topic.gjs@@ -143,7 +143,7 @@ export default class FeatureTopic extends Component {<:body>{{#if @model.topic.pinned_at}}<div class="feature-section">- <div class="desc">+ <div class="feature-section__description">{{#if @model.topic.pinned_globally}}<p><ConditionalLoadingSpinner@@ -211,10 +211,10 @@ export default class FeatureTopic extends Component {/>{{/if}}{{/if}}- <hr />{{#if @model.topic.details.can_banner_topic}}+ <hr /><div class="feature-section">- <div class="desc">+ <div class="feature-section__description"><p><ConditionalLoadingSpinner@size="small"diff --git a/frontend/discourse/app/components/modal/feature-topic/pin-option-section.gjs b/frontend/discourse/app/components/modal/feature-topic/pin-option-section.gjsindex d4dddcb6e11..f72e31cbdb5 100644--- a/frontend/discourse/app/components/modal/feature-topic/pin-option-section.gjs+++ b/frontend/discourse/app/components/modal/feature-topic/pin-option-section.gjs@@ -1,12 +1,11 @@import Component from "@glimmer/component";-import { tracked } from "@glimmer/tracking";+import { cached } from "@glimmer/tracking";import { action } from "@ember/object";import { service } from "@ember/service";import { trustHTML } from "@ember/template";import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";-import DButton from "discourse/components/d-button";+import Form from "discourse/components/form";import FutureDateInput from "discourse/components/future-date-input";-import PopupInputTip from "discourse/components/popup-input-tip";import icon from "discourse/helpers/d-icon";import { FORMAT } from "discourse/select-kit/components/future-date-input-selector";import { i18n } from "discourse-i18n";@@ -15,31 +14,31 @@ export const MAX_GLOBALLY_PINNED_TOPICS = 4;export default class PinOptionSection extends Component {@service dialog;- @service site;- @tracked tipShownAt = false;+ @cached+ get formData() {+ return { pinUntil: this.args.dateValue };+ }- get validation() {- if (!this._isDateValid()) {- return {- failed: true,- reason: i18n("topic.feature_topic.pin_validation"),- };+ @action+ validatePinUntil(name, value, { addError }) {+ const parsed = moment(value, FORMAT);+ if (!parsed.isValid() || parsed <= moment()) {+ addError(name, {+ title: i18n("topic.feature_topic.pin_until"),+ message: i18n("topic.feature_topic.pin_validation"),+ });}}- _isDateValid() {- const parsed = moment(this.args.dateValue, FORMAT);- return parsed.isValid() && parsed > moment();+ @action+ handleDateSet(value, { set }) {+ set("pinUntil", value);+ this.args.onDateChange?.(value);}@action- pin() {- if (!this._isDateValid()) {- this.tipShownAt = Date.now();- return;- }-+ handleSubmit() {if (this.args.confirmMessage) {this.dialog.yesNoConfirm({message: this.args.confirmMessage,@@ -51,8 +50,13 @@ export default class PinOptionSection extends Component {}<template>- <div class="feature-section">- <div class="desc">+ <Form+ @data={{this.formData}}+ @onSubmit={{this.handleSubmit}}+ class="feature-section"+ as |form|+ >+ <div class="feature-section__description">{{#if @statsMessage}}<p><ConditionalLoadingSpinner @size="small" @condition={{@loading}}>@@ -62,50 +66,30 @@ export default class PinOptionSection extends Component {{{/if}}<p>{{@noteMessage}}</p>+ <p class="feature-section__pin-message">{{trustHTML @pinMessage}}+ {{icon "far-clock"}}</p>- {{#if this.site.mobileView}}- <p>{{trustHTML @pinMessage}}</p>-- <p class="with-validation">+ <form.Field+ @name="pinUntil"+ @title={{i18n "topic.feature_topic.pin_until"}}+ @showTitle={{false}}+ @type="custom"+ @validate={{this.validatePinUntil}}+ @onSet={{this.handleDateSet}}+ as |field|+ >+ <field.Control><FutureDateInputclass="pin-until"@clearable={{true}}- @input={{@dateValue}}- @onChangeInput={{@onDateChange}}- />- <PopupInputTip- @validation={{this.validation}}- @shownAt={{this.tipShownAt}}+ @input={{field.value}}+ @onChangeInput={{field.set}}/>- </p>- {{else}}- <p class="with-validation">- {{trustHTML @pinMessage}}- <span>- {{icon "far-clock"}}- <FutureDateInput- class="pin-until"- @clearable={{true}}- @input={{@dateValue}}- @onChangeInput={{@onDateChange}}- />- <PopupInputTip- @validation={{this.validation}}- @shownAt={{this.tipShownAt}}- />- </span>- </p>- {{/if}}+ </field.Control>+ </form.Field>- <p>- <DButton- @action={{this.pin}}- @icon="thumbtack"- @label={{@buttonLabel}}- class="btn-primary"- />- </p>+ <form.Submit @label={{@buttonLabel}} /></div>- </div>+ </Form></template>}