@fluid-topics/ft-reader-feedback 1.0.57 → 1.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { nothing } from "lit";
2
2
  import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
3
  import { FtReaderFeedbackProperties } from "./ft-reader-feedback.properties";
4
4
  import { FtTopicRatingSummary } from "@fluid-topics/ft-reader-context/build/store/model";
5
- import type { FtPublicationRatingSummary, FtUserProfile } from "@fluid-topics/public-api";
5
+ import type { FtPublicationRatingSummary, FtSession } from "@fluid-topics/public-api";
6
6
  import { FtReaderFeedbackConfiguration } from "@fluid-topics/public-api";
7
7
  import { FtTextArea } from "@fluid-topics/ft-text-area";
8
8
  import { FtIconVariants } from "@fluid-topics/ft-icon/build/ft-icon.properties";
@@ -27,7 +27,7 @@ export declare class FtReaderFeedback extends FtReaderFeedback_base implements F
27
27
  ratingAllowed: boolean;
28
28
  i18nProperties: FeedbackI18nProperties;
29
29
  ratingSummary?: FtPublicationRatingSummary | FtTopicRatingSummary;
30
- user?: FtUserProfile;
30
+ session?: FtSession;
31
31
  feedbackInput: FtTextArea;
32
32
  from: string;
33
33
  feedbackMessage: string;
@@ -54,6 +54,7 @@ export declare class FtReaderFeedback extends FtReaderFeedback_base implements F
54
54
  private renderRating;
55
55
  private rate;
56
56
  private renderFeedbackSection;
57
+ private onFormSubmitEvent;
57
58
  private validFromEmail;
58
59
  private sendFeedback;
59
60
  private placeholderInEditor;
@@ -21,7 +21,7 @@ import { withI18n } from "@fluid-topics/ft-i18n";
21
21
  import { defaultDesignerMessages, designer } from "./utils/InDesignerFeedbackComponentMessages";
22
22
  import { FtTextField } from "@fluid-topics/ft-text-field";
23
23
  import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registration";
24
- import { FtReaderFeatures } from "@fluid-topics/ft-reader-context/build/store/utils/FtReaderService";
24
+ import { FtReaderFeatures } from "@fluid-topics/ft-reader-context";
25
25
  class FtReaderFeedback extends withI18n(FtReaderComponent) {
26
26
  constructor() {
27
27
  super();
@@ -41,14 +41,14 @@ class FtReaderFeedback extends withI18n(FtReaderComponent) {
41
41
  }
42
42
  get canAccessFeedback() {
43
43
  var _a;
44
- return this.user && userHasRole(this.user.roles, "FEEDBACK_USER") && ((_a = this.service) === null || _a === void 0 ? void 0 : _a.isFeatureAccessible(FtReaderFeatures.FEEDBACK));
44
+ return (_a = this.service) === null || _a === void 0 ? void 0 : _a.isFeatureAccessible(FtReaderFeatures.FEEDBACK, { session: this.session });
45
45
  }
46
46
  get canAccessRating() {
47
- var _a;
48
- return this.userHasRatingRole && this.configuredRatingType !== "NO_RATING" && ((_a = this.service) === null || _a === void 0 ? void 0 : _a.isFeatureAccessible(FtReaderFeatures.RATING));
47
+ var _a, _b;
48
+ return (_a = this.service) === null || _a === void 0 ? void 0 : _a.isFeatureAccessible(FtReaderFeatures.RATING, { session: this.session, ratingType: (_b = this.ratingSummary) === null || _b === void 0 ? void 0 : _b.type });
49
49
  }
50
50
  get userHasRatingRole() {
51
- return this.user && userHasRole(this.user.roles, "RATING_USER");
51
+ return this.session && userHasRole(this.session, "RATING_USER");
52
52
  }
53
53
  get configuredRatingType() {
54
54
  var _a, _b;
@@ -74,10 +74,10 @@ class FtReaderFeedback extends withI18n(FtReaderComponent) {
74
74
  return html `
75
75
  <div class="ft-reader-feedback">
76
76
  ${this.hideTitle ? nothing : html `
77
- <ft-typography variant="title" part="main-title">
78
- ${this.i18n(this.i18nProperties.feedbackMainTitle)}
79
- </ft-typography>
80
- `}
77
+ <ft-typography variant="title" part="main-title">
78
+ ${this.i18n(this.i18nProperties.feedbackMainTitle)}
79
+ </ft-typography>
80
+ `}
81
81
  ${this.renderRatingSection()}
82
82
  ${this.renderFeedbackSection()}
83
83
  </div>
@@ -127,17 +127,17 @@ class FtReaderFeedback extends withI18n(FtReaderComponent) {
127
127
  let active = this.ratingType === "STARS" && this.ratingValue > index;
128
128
  const ratingValue = index + 1;
129
129
  return html `
130
- <ft-button round part="rating-stars-${ratingValue}"
131
- label="${feedback.messages.starsRating(ratingValue)}"
132
- tooltipPosition="top"
133
- .iconVariant=${this.iconVariant}
134
- icon="${active ? this.filledStarIcon : this.emptyStarIcon}"
135
- class="ft-reader-feedback--${active ? "active" : "inactive"}"
136
- @click=${() => this.rate(this.ratingValue === ratingValue
130
+ <ft-button round part="rating-stars-${ratingValue}"
131
+ label="${feedback.messages.starsRating(ratingValue)}"
132
+ tooltipPosition="top"
133
+ .iconVariant=${this.iconVariant}
134
+ icon="${active ? this.filledStarIcon : this.emptyStarIcon}"
135
+ class="ft-reader-feedback--${active ? "active" : "inactive"}"
136
+ @click=${() => this.rate(this.ratingValue === ratingValue
137
137
  ? undefined
138
138
  : ratingValue)}
139
- ></ft-button>
140
- `;
139
+ ></ft-button>
140
+ `;
141
141
  })}
142
142
  </div>
143
143
  `;
@@ -188,14 +188,14 @@ class FtReaderFeedback extends withI18n(FtReaderComponent) {
188
188
  }
189
189
  }
190
190
  renderFeedbackSection() {
191
- var _a, _b;
191
+ var _a, _b, _c;
192
192
  if (this.canAccessFeedback) {
193
193
  const mailLink = this.feedbackMailLinkBuilder(this.feedbackMessage);
194
194
  let button = html `
195
195
  <ft-button primary
196
+ type="submit" name="submit"
196
197
  class="ft-reader-feedback--send-feedback"
197
198
  ?disabled=${!this.feedbackMessage || !this.validFromEmail()}
198
- @click=${() => mailLink ? this.onMailerFeedbackSent() : this.sendFeedback()}
199
199
  part="send-feedback">
200
200
  ${feedback.messages.okButton()}
201
201
  </ft-button>
@@ -208,17 +208,18 @@ class FtReaderFeedback extends withI18n(FtReaderComponent) {
208
208
  `;
209
209
  }
210
210
  return html `
211
- <div class="ft-reader-feedback--feedback" part="feedback-container">
211
+ <form class="ft-reader-feedback--feedback" part="feedback-container" autocomplete="on"
212
+ @submit="${(e) => this.onFormSubmitEvent(e, !!mailLink)}">
212
213
  <ft-typography variant="title-dense" part="section-title" class="ft-reader-feedback--section-title">
213
214
  ${this.i18n(this.i18nProperties.feedbackSectionTitle)}
214
215
  </ft-typography>
215
- ${((_a = this.user) === null || _a === void 0 ? void 0 : _a.userId) == null && ((_b = this.configuration) === null || _b === void 0 ? void 0 : _b.mailsSentByFluidTopicsForUnauthenticatedUsers) ? html `
216
- <ft-text-field outlined
217
- class="ft-reader-feedback--from-input"
218
- label=${feedback.messages.feedbackfromEmail()}
219
- @live-change=${(e) => this.from = e.detail.trim()}
220
- ?error=${this.from && !this.validFromEmail()}
221
- helper=${this.from && !this.validFromEmail() ? feedback.messages.feedbackfromEmailInvalid() : ""}
216
+ ${((_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.profile) === null || _b === void 0 ? void 0 : _b.userId) == null && ((_c = this.configuration) === null || _c === void 0 ? void 0 : _c.mailsSentByFluidTopicsForUnauthenticatedUsers) ? html `
217
+ <ft-text-field outlined name="email" type="email" autocomplete="email"
218
+ class="ft-reader-feedback--from-input"
219
+ label=${feedback.messages.feedbackfromEmail()}
220
+ @change=${(e) => this.from = e.detail.trim()}
221
+ ?error=${this.from && !this.validFromEmail()}
222
+ helper=${this.from && !this.validFromEmail() ? feedback.messages.feedbackfromEmailInvalid() : ""}
222
223
  />
223
224
  ` : nothing}
224
225
  <ft-text-area outlined
@@ -227,15 +228,19 @@ class FtReaderFeedback extends withI18n(FtReaderComponent) {
227
228
  @live-change=${(e) => this.feedbackMessage = e.detail.trim()}
228
229
  ></ft-text-area>
229
230
  ${button}
230
- </div>
231
+ </form>
231
232
  `;
232
233
  }
233
234
  return this.placeholderInEditor(designer.messages.missingFeedbackRole());
234
235
  }
236
+ onFormSubmitEvent(event, isUsingMailLink) {
237
+ event.preventDefault();
238
+ isUsingMailLink ? this.onMailerFeedbackSent() : this.sendFeedback();
239
+ }
235
240
  validFromEmail() {
236
- var _a, _b;
241
+ var _a, _b, _c;
237
242
  const expression = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/;
238
- return !(((_a = this.user) === null || _a === void 0 ? void 0 : _a.userId) == null && ((_b = this.configuration) === null || _b === void 0 ? void 0 : _b.mailsSentByFluidTopicsForUnauthenticatedUsers))
243
+ return !(((_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.profile) === null || _b === void 0 ? void 0 : _b.userId) == null && ((_c = this.configuration) === null || _c === void 0 ? void 0 : _c.mailsSentByFluidTopicsForUnauthenticatedUsers))
239
244
  || expression.test(this.from);
240
245
  }
241
246
  sendFeedback() {
@@ -293,7 +298,7 @@ __decorate([
293
298
  ], FtReaderFeedback.prototype, "ratingSummary", void 0);
294
299
  __decorate([
295
300
  property({ attribute: false })
296
- ], FtReaderFeedback.prototype, "user", void 0);
301
+ ], FtReaderFeedback.prototype, "session", void 0);
297
302
  __decorate([
298
303
  query(".ft-reader-feedback--feedback-input")
299
304
  ], FtReaderFeedback.prototype, "feedbackInput", void 0);