Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: UI for telegram user notifications #1649

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ jobs:
run_install: false

- name: Check bundle size
uses: andresz1/size-limit-action@v1
uses: andresz1/size-limit-action@dd31dce7dcc72a041fd3e49abf0502b13fc4ce05
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
directory: ./frontend/apps/remark42
package_manager: pnpm

test:
name: Tests & Coverage
Expand Down
2 changes: 1 addition & 1 deletion backend/app/rest/api/rest_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (s *private) telegramSubscribeCtrl(w http.ResponseWriter, r *http.Request)
var address, siteID string
address, siteID, err := s.telegramService.CheckToken(queryToken, user.ID)
if err != nil {
rest.SendErrorJSON(w, r, http.StatusInternalServerError, err, "can't set telegram for user", rest.ErrInternal)
rest.SendErrorJSON(w, r, http.StatusNotFound, err, "request is not verified yet", rest.ErrInternal)
return
}

Expand Down
4 changes: 2 additions & 2 deletions backend/app/rest/api/rest_private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,8 @@ func TestRest_TelegramNotification(t *testing.T) {
body, err = io.ReadAll(resp.Body)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
require.Equal(t, http.StatusInternalServerError, resp.StatusCode, string(body))
require.Equal(t, `{"code":0,"details":"can't set telegram for user","error":"not verified"}`+"\n", string(body))
require.Equal(t, http.StatusNotFound, resp.StatusCode, string(body))
require.Equal(t, `{"code":0,"details":"request is not verified yet","error":"not verified"}`+"\n", string(body))

mockTlgrm.notVerified = false

Expand Down
28 changes: 28 additions & 0 deletions frontend/apps/remark42/app/common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@

/* Subscription methods */

/**
* Start process of telegram subscription to updates
*/
export const telegramSubscribe = (): Promise<{
bot: string;
token: string;
}> => apiFetcher.get('/telegram/subscribe');

Check warning on line 87 in frontend/apps/remark42/app/common/api.ts

View check run for this annotation

Codecov / codecov/patch

frontend/apps/remark42/app/common/api.ts#L87

Added line #L87 was not covered by tests

/**
* Start process of telegram subscription to updates
* Example of error response: {"code":0,"details":"can't set telegram for user","error":"request is not verified yet"}
* Example of success response: {"address":"223211010","updated":true}
*/
export const telegramCurrentSubscribtion = ({
token,
}: {
token: string;
}): Promise<{
address: string;
updated: boolean;
}> => apiFetcher.get('/telegram/subscribe', { tkn: token });

Check warning on line 101 in frontend/apps/remark42/app/common/api.ts

View check run for this annotation

Codecov / codecov/patch

frontend/apps/remark42/app/common/api.ts#L101

Added line #L101 was not covered by tests

/**
* Start process of telegram subscription to updates
* Example of success response: {"deleted":true}
*/
export const telegramUnsubcribe = (): Promise<{ deleted: boolean }> => apiFetcher.delete('/telegram');

/**
* Start process of email subscription to updates
* @param emailAddress email for subscription
Expand Down
1 change: 1 addition & 0 deletions frontend/apps/remark42/app/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function includes<T extends U, U>(coll: ReadonlyArray<T>, el: U): el is T {
export const rawParams = parseQuery();
export const maxShownComments = parseNumber(rawParams.max_shown_comments) ?? MAX_SHOWN_ROOT_COMMENTS;
export const isEmailSubscription = rawParams.show_email_subscription !== 'false';
export const isTelegramSubscription = rawParams.show_telegram_subscription !== 'false';
export const isRssSubscription =
rawParams.show_rss_subscription === undefined || rawParams.show_rss_subscription !== 'false';
export const theme = (rawParams.theme = includes(THEMES, rawParams.theme) ? rawParams.theme : THEMES[0]);
Expand Down
28 changes: 0 additions & 28 deletions frontend/apps/remark42/app/components/auth/auth.messsages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,6 @@ export const messages = defineMessages<string>({
id: 'auth.submit',
defaultMessage: 'Submit',
},
telegramLink: {
id: 'auth.telegram-link',
defaultMessage: 'by the link',
},
telegramCheck: {
id: 'auth.telegram-check',
defaultMessage: 'Check',
},
telegramQR: {
id: 'auth.telegram-qr',
defaultMessage: 'Telegram QR-code',
},
telegramMessage1: {
id: 'auth.telegram-message-1',
defaultMessage: 'Open Telegram',
},
telegramOptionalQR: {
id: 'auth.telegram-optional-qr',
defaultMessage: 'or by scanning the QR code',
},
telegramMessage2: {
id: 'auth.telegram-message-2',
defaultMessage: 'and click “Start” there.',
},
telegramMessage3: {
id: 'auth.telegram-message-3',
defaultMessage: 'Afterwards, click “Check” below.',
},
openProfile: {
id: 'auth.open-profile',
defaultMessage: 'Open My Profile',
Expand Down
12 changes: 0 additions & 12 deletions frontend/apps/remark42/app/components/auth/auth.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,3 @@
color: var(--error-color);
line-height: 1.2;
}

.telegramQR {
background-color: rgb(var(--white-color));
box-sizing: border-box;
display: block;
margin: 12px auto;
padding: 10px;
}

.telegram {
margin-bottom: 0;
}
35 changes: 7 additions & 28 deletions frontend/apps/remark42/app/components/auth/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useState, useRef } from 'preact/hooks';
import { useIntl } from 'react-intl';
import { useDispatch } from 'react-redux';

import { BASE_URL, API_BASE } from 'common/constants.config';
import { setUser } from 'store/user/actions';
import { Input } from 'components/input';
import { TelegramLink } from 'components/telegram/telegram-link';
import { CrossIcon } from 'components/icons/cross';
import { TextareaAutosize } from 'components/textarea-autosize';
import { Spinner } from 'components/spinner/spinner';
Expand Down Expand Up @@ -234,33 +234,12 @@ export function Auth() {
<CrossIcon />
</button>
</div>
<p className={clsx('telegram', styles.telegram)}>
{intl.formatMessage(messages.telegramMessage1)}{' '}
<a
target="_blank"
rel="noopener noreferrer"
href={`https://t.me/${telegramParamsRef.current.bot}/?start=${telegramParamsRef.current.token}`}
>
{intl.formatMessage(messages.telegramLink)}
</a>
{window.screen.width >= 768 && ` ${intl.formatMessage(messages.telegramOptionalQR)}`}{' '}
{intl.formatMessage(messages.telegramMessage2)}
<br />
{intl.formatMessage(messages.telegramMessage3)}
</p>
{window.screen.width >= 768 && (
<img
src={`${BASE_URL}${API_BASE}/qr/telegram?url=https://t.me/${telegramParamsRef.current.bot}/?start=${telegramParamsRef.current.token}`}
height="200"
width="200"
className={clsx('telegram-qr', styles.telegramQR)}
alt={intl.formatMessage(messages.telegramQR)}
/>
)}
{errorMessage && <div className={clsx('auth-error', styles.error)}>{errorMessage}</div>}
<Button key="submit" className="auth-submit" type="submit" onClick={handleTelegramSubmit}>
{intl.formatMessage(messages.telegramCheck)}
</Button>
<TelegramLink
onSubmit={handleTelegramSubmit}
errorMessage={errorMessage}
bot={telegramParamsRef.current.bot}
token={telegramParamsRef.current.token}
/>
</>
) : view === 'token' ? (
<>
Expand Down
11 changes: 9 additions & 2 deletions frontend/apps/remark42/app/components/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx';
import { h, JSX } from 'preact';
import { forwardRef } from 'preact/compat';
import b, { Mods, Mix } from 'bem-react-helper';
Expand All @@ -11,11 +12,17 @@ export type ButtonProps = Omit<JSX.HTMLAttributes, 'size' | 'className'> & {
mods?: Mods;
mix?: Mix;
type?: string;
className?: string;
};

export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ children, theme, mods, mix, kind, type = 'button', size, ...props }, ref) => (
<button className={b('button', { mods: { kind, size, theme }, mix }, { ...mods })} type={type} {...props} ref={ref}>
({ children, theme, mods, mix, kind, type = 'button', size, className, ...props }, ref) => (
<button
className={clsx(b('button', { mods: { kind, size, theme }, mix }, { ...mods }), className)}
type={type}
{...props}
ref={ref}
>
{children}
</button>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.root {
display: flex;
flex-wrap: wrap;
flex-direction: column;
padding: 8px;
width: 250px;
box-sizing: border-box;
line-height: 1.2;
text-align: left;
}

.preloader {
margin: 0 auto;
filter: invert(1);
}
Loading
Loading