@financial-times/qanda-ui 0.0.1-beta.5 → 0.0.1-beta.6

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.
@@ -11,6 +11,7 @@ const QuestionForm_1 = __importDefault(require("./QuestionForm"));
11
11
  const UserInfo_1 = __importDefault(require("./UserInfo"));
12
12
  const QandaOComments_1 = __importDefault(require("./QandaOComments"));
13
13
  const Stream_1 = __importDefault(require("./Stream"));
14
+ const Calendar_1 = __importDefault(require("./Calendar"));
14
15
  const CountdownTimer_1 = __importDefault(require("./CountdownTimer"));
15
16
  const FloatingActionBar_1 = __importDefault(require("./FloatingActionBar"));
16
17
  const EmbedFormField_1 = __importDefault(require("./EmbedFormField"));
@@ -31,12 +32,12 @@ function QandaContainer({ embedFormFieldContainer, countdownTimerContainer, }) {
31
32
  });
32
33
  const status = updatedQA?.status || data?.status || 'pre-live';
33
34
  (0, react_1.useEffect)(() => {
34
- dispatch((0, user_1.getUserProfile)({ useStaging }));
35
+ dispatch((0, user_1.getUserProfile)({ useStaging, commentsAPIUrl }));
35
36
  return () => {
36
37
  // ensure we reset the api state when the component is unmounted
37
38
  dispatch(comments_api_1.nextCommentsApi.util.resetApiState());
38
39
  };
39
40
  }, [dispatch, storyId]);
40
- return ((0, jsx_runtime_1.jsxs)("div", { className: "qanda-container", "data-trackable": "liveqa", children: [error && ((0, jsx_runtime_1.jsxs)("p", { children: ["We are not able to load the Q&A at the moment. Please try again later. Error:", error] })), !isLoading && !error && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [status !== 'close' && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(QuestionForm_1.default, {}), (0, jsx_runtime_1.jsx)(CountdownTimer_1.default, { container: countdownTimerContainer })] })), (0, jsx_runtime_1.jsx)(Stream_1.default, {}), status !== 'close' && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(UserInfo_1.default, {}), (0, jsx_runtime_1.jsx)(QandaOComments_1.default, {})] })), data?.status === 'live' && (0, jsx_runtime_1.jsx)(FloatingActionBar_1.default, {}), (0, jsx_runtime_1.jsx)(EmbedFormField_1.default, { container: embedFormFieldContainer })] }))] }));
41
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "qanda-container", "data-trackable": "liveqa", children: [error && ((0, jsx_runtime_1.jsxs)("p", { children: ["We are not able to load the Q&A at the moment. Please try again later. Error:", error] })), !isLoading && !error && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [status !== 'close' && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(QuestionForm_1.default, {}), (0, jsx_runtime_1.jsx)(CountdownTimer_1.default, { container: countdownTimerContainer })] })), status === 'pre-live' && (0, jsx_runtime_1.jsx)(Calendar_1.default, {}), (0, jsx_runtime_1.jsx)(Stream_1.default, {}), status !== 'close' && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(UserInfo_1.default, {}), (0, jsx_runtime_1.jsx)(QandaOComments_1.default, {})] })), data?.status === 'live' && (0, jsx_runtime_1.jsx)(FloatingActionBar_1.default, {}), (0, jsx_runtime_1.jsx)(EmbedFormField_1.default, { container: embedFormFieldContainer })] }))] }));
41
42
  }
42
43
  exports.default = QandaContainer;
@@ -69,7 +69,11 @@ function QuestionForm() {
69
69
  dispatch((0, questionSlice_1.updateDisplayNameError)(`The display name contains invalid characters: ${invalidCharacters}`));
70
70
  return;
71
71
  }
72
- updatedProfile = await dispatch((0, user_1.getUserProfile)({ useStaging, displayName: newDisplayName })).unwrap();
72
+ updatedProfile = await dispatch((0, user_1.getUserProfile)({
73
+ useStaging,
74
+ displayName: newDisplayName,
75
+ commentsAPIUrl,
76
+ })).unwrap();
73
77
  // The user token is empty when there is no display name set
74
78
  // if there are also no errors, we can assume the display name is taken
75
79
  if (!updatedProfile?.token && !userDisplayNameError) {
@@ -20,8 +20,12 @@ const initialState = {
20
20
  loading: false,
21
21
  error: '',
22
22
  };
23
- exports.getUserProfile = (0, toolkit_1.createAsyncThunk)(ACTION_GET_USER_PROFILE, async ({ useStaging, displayName = '' }) => {
24
- const userDetails = await (0, auth_1.default)({ useStaging, displayName });
23
+ exports.getUserProfile = (0, toolkit_1.createAsyncThunk)(ACTION_GET_USER_PROFILE, async ({ useStaging, displayName = '', commentsAPIUrl }) => {
24
+ const userDetails = await (0, auth_1.default)({
25
+ useStaging,
26
+ displayName,
27
+ commentsAPIUrl,
28
+ });
25
29
  return userDetails;
26
30
  });
27
31
  exports.user = (0, toolkit_1.createSlice)({
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- // eslint-disable-next-line import/no-extraneous-dependencies
7
- const auth_1 = __importDefault(require("@financial-times/o-comments/src/js/utils/auth"));
8
- // TODO: make these options settable, but for now we want to use staging
9
- exports.default = async ({ useStaging = true, displayName = '', }) => {
10
- const userDetails = await auth_1.default.fetchJsonWebToken({
3
+ const o_comments_1 = require("@financial-times/o-comments");
4
+ const PROD_AUTH_URL = 'https://comments-api.ft.com';
5
+ const TEST_AUTH_URL = 'https://comments-api-test.ft.com';
6
+ exports.default = async ({ useStaging = true, displayName = '', commentsAPIUrl = PROD_AUTH_URL, }) => {
7
+ const userDetails = await o_comments_1.auth.fetchJsonWebToken({
11
8
  useStagingEnvironment: useStaging,
12
9
  onlySubscribers: true,
13
10
  displayName,
11
+ commentsAPIUrl: commentsAPIUrl === PROD_AUTH_URL ? PROD_AUTH_URL : TEST_AUTH_URL,
14
12
  });
15
13
  // if the JWT creation has failed, a `userHasValidSession` value will be returned
16
14
  // our application assumes the values of a JWT are saved to state, so we set the
@@ -6,6 +6,7 @@ import QuestionForm from './QuestionForm';
6
6
  import UserInfo from './UserInfo';
7
7
  import QandaOComments from './QandaOComments';
8
8
  import Stream from './Stream';
9
+ import Calendar from './Calendar';
9
10
  import CountdownTimer from './CountdownTimer';
10
11
  import FloatingActionBar from './FloatingActionBar';
11
12
  import EmbedFormField from './EmbedFormField';
@@ -26,12 +27,12 @@ function QandaContainer({ embedFormFieldContainer, countdownTimerContainer, }) {
26
27
  });
27
28
  const status = updatedQA?.status || data?.status || 'pre-live';
28
29
  useEffect(() => {
29
- dispatch(getUserProfile({ useStaging }));
30
+ dispatch(getUserProfile({ useStaging, commentsAPIUrl }));
30
31
  return () => {
31
32
  // ensure we reset the api state when the component is unmounted
32
33
  dispatch(nextCommentsApi.util.resetApiState());
33
34
  };
34
35
  }, [dispatch, storyId]);
35
- return (_jsxs("div", { className: "qanda-container", "data-trackable": "liveqa", children: [error && (_jsxs("p", { children: ["We are not able to load the Q&A at the moment. Please try again later. Error:", error] })), !isLoading && !error && (_jsxs(_Fragment, { children: [status !== 'close' && (_jsxs(_Fragment, { children: [_jsx(QuestionForm, {}), _jsx(CountdownTimer, { container: countdownTimerContainer })] })), _jsx(Stream, {}), status !== 'close' && (_jsxs(_Fragment, { children: [_jsx(UserInfo, {}), _jsx(QandaOComments, {})] })), data?.status === 'live' && _jsx(FloatingActionBar, {}), _jsx(EmbedFormField, { container: embedFormFieldContainer })] }))] }));
36
+ return (_jsxs("div", { className: "qanda-container", "data-trackable": "liveqa", children: [error && (_jsxs("p", { children: ["We are not able to load the Q&A at the moment. Please try again later. Error:", error] })), !isLoading && !error && (_jsxs(_Fragment, { children: [status !== 'close' && (_jsxs(_Fragment, { children: [_jsx(QuestionForm, {}), _jsx(CountdownTimer, { container: countdownTimerContainer })] })), status === 'pre-live' && _jsx(Calendar, {}), _jsx(Stream, {}), status !== 'close' && (_jsxs(_Fragment, { children: [_jsx(UserInfo, {}), _jsx(QandaOComments, {})] })), data?.status === 'live' && _jsx(FloatingActionBar, {}), _jsx(EmbedFormField, { container: embedFormFieldContainer })] }))] }));
36
37
  }
37
38
  export default QandaContainer;
@@ -63,7 +63,11 @@ export default function QuestionForm() {
63
63
  dispatch(updateDisplayNameError(`The display name contains invalid characters: ${invalidCharacters}`));
64
64
  return;
65
65
  }
66
- updatedProfile = await dispatch(getUserProfile({ useStaging, displayName: newDisplayName })).unwrap();
66
+ updatedProfile = await dispatch(getUserProfile({
67
+ useStaging,
68
+ displayName: newDisplayName,
69
+ commentsAPIUrl,
70
+ })).unwrap();
67
71
  // The user token is empty when there is no display name set
68
72
  // if there are also no errors, we can assume the display name is taken
69
73
  if (!updatedProfile?.token && !userDisplayNameError) {
@@ -14,8 +14,12 @@ const initialState = {
14
14
  loading: false,
15
15
  error: '',
16
16
  };
17
- export const getUserProfile = createAsyncThunk(ACTION_GET_USER_PROFILE, async ({ useStaging, displayName = '' }) => {
18
- const userDetails = await auth({ useStaging, displayName });
17
+ export const getUserProfile = createAsyncThunk(ACTION_GET_USER_PROFILE, async ({ useStaging, displayName = '', commentsAPIUrl }) => {
18
+ const userDetails = await auth({
19
+ useStaging,
20
+ displayName,
21
+ commentsAPIUrl,
22
+ });
19
23
  return userDetails;
20
24
  });
21
25
  export const user = createSlice({
@@ -1,11 +1,12 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import auth from '@financial-times/o-comments/src/js/utils/auth';
3
- // TODO: make these options settable, but for now we want to use staging
4
- export default async ({ useStaging = true, displayName = '', }) => {
1
+ import { auth } from '@financial-times/o-comments';
2
+ const PROD_AUTH_URL = 'https://comments-api.ft.com';
3
+ const TEST_AUTH_URL = 'https://comments-api-test.ft.com';
4
+ export default async ({ useStaging = true, displayName = '', commentsAPIUrl = PROD_AUTH_URL, }) => {
5
5
  const userDetails = await auth.fetchJsonWebToken({
6
6
  useStagingEnvironment: useStaging,
7
7
  onlySubscribers: true,
8
8
  displayName,
9
+ commentsAPIUrl: commentsAPIUrl === PROD_AUTH_URL ? PROD_AUTH_URL : TEST_AUTH_URL,
9
10
  });
10
11
  // if the JWT creation has failed, a `userHasValidSession` value will be returned
11
12
  // our application assumes the values of a JWT are saved to state, so we set the
@@ -1,9 +1,9 @@
1
1
  export type UserDetails = {
2
2
  token: string;
3
3
  displayName: string;
4
- isRegistered: boolean;
5
- isTrialist: boolean;
6
- isSubscribed: boolean;
4
+ isRegistered?: boolean;
5
+ isTrialist?: boolean;
6
+ isSubscribed?: boolean;
7
7
  };
8
8
  export type UserState = {
9
9
  profile: UserDetails;
@@ -11,6 +11,7 @@ export type UserState = {
11
11
  export declare const getUserProfile: import("@reduxjs/toolkit").AsyncThunk<UserDetails, {
12
12
  useStaging: boolean;
13
13
  displayName?: string;
14
+ commentsAPIUrl: string;
14
15
  }, {
15
16
  state?: unknown;
16
17
  dispatch?: import("redux-thunk").ThunkDispatch<unknown, unknown, import("redux").UnknownAction>;
@@ -1,5 +1,6 @@
1
- declare const _default: ({ useStaging, displayName, }: {
1
+ declare const _default: ({ useStaging, displayName, commentsAPIUrl, }: {
2
2
  useStaging: boolean;
3
3
  displayName: string;
4
- }) => Promise<any>;
4
+ commentsAPIUrl?: string;
5
+ }) => Promise<import("@financial-times/o-comments").AuthResponse>;
5
6
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/qanda-ui",
3
- "version": "0.0.1-beta.5",
3
+ "version": "0.0.1-beta.6",
4
4
  "description": "Components for the Live Q&A UI",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -108,7 +108,7 @@
108
108
  "@dotcom-reliability-kit/client-metrics-web": "^0.1.2",
109
109
  "@financial-times/n-tracking": "^7.6.0",
110
110
  "@financial-times/o-colors": "^6.7",
111
- "@financial-times/o-comments": "^12.0.0",
111
+ "@financial-times/o-comments": "^13.0.0",
112
112
  "@financial-times/o-forms": "^10.0.2",
113
113
  "@financial-times/o-icons": "^7.8",
114
114
  "@financial-times/o-labels": "^7.0.1",