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: refactor msg template components; add telegram character limit #1148

Merged
merged 7 commits into from
May 5, 2021

Conversation

zwliew
Copy link
Contributor

@zwliew zwliew commented Apr 22, 2021

Problem

Currently, the SMSTemplate and TelegramTemplate components are nearly identical. The only difference is that SMSTemplate has an error message (which I'll also add to the Telegram template in this PR)

Since they're nearly identical, some unit tests written for both components will be duplicated for both of them as well (ref: #1118 (comment)).

To reduce code and test duplication, refactor both components to a common component.

Solution

Features:

  • Replace exceedsCharacterThreshold with warningCharacterCount and errorCharacterCount thresholds
    • warningCharacterCount merely displays an error message
    • errorCharacterCount displays an error message and disables the Next button
  • Add a set of warning and error thresholds for the Telegram template as well

Improvements:

  • Refactor SMSTemplate and TelegramTemplate to a common component
  • Refactor the tests accordingly

Before & After Screenshots

To be added

The only visual difference is the Telegram template should look exactly the same as the SMS template now.

Tests

SMS and Telegram templates should function just as before

  1. Clicking next button goes next
  2. Exceeding the warn threshold of 1000 chars displays an error message

Exceeding error threshold should display error msg and disable the next button

  1. Type >1600 chars for SMS and >4096 chars for Telegram
  2. The next button should be disabled and an error msg should be displayed

Deploy Notes

No deploy notes.

Todo

  • Refactor the tests

@zwliew zwliew changed the title feat: refactor body template component; add telegram character limit feat: refactor msg template components; add telegram character limit Apr 22, 2021
@@ -11,40 +12,51 @@ import {
StepSection,
} from 'components/common'
import SaveDraftModal from 'components/dashboard/create/save-draft-modal'
import { exceedsCharacterThreshold, saveTemplate } from 'services/sms.service'
import { saveTemplate } from 'services/sms.service'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component does not work with Telegram.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my bad. I guess this is a case where frontend tests would've caught the error haha

Copy link
Contributor

@lamkeewei lamkeewei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix to make it work for Telegram. Maybe pass the saveTemplate function as a prop?

@zwliew
Copy link
Contributor Author

zwliew commented Apr 26, 2021

I think I'll move the unit tests for this component to this PR

@zwliew zwliew force-pushed the refactor-frontend-templates branch from 7be2fa8 to 9cc7c23 Compare May 3, 2021 02:36
Copy link
Contributor

@lamkeewei lamkeewei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Tested the following an works as expected:

  1. Existing Telegram/SMS template saving should works as expected
  2. Warning shown when character limits are reached for both SMS/Telegram

@lamkeewei lamkeewei merged commit 6944401 into develop May 5, 2021
@lamkeewei lamkeewei deleted the refactor-frontend-templates branch May 5, 2021 09:34
lamkeewei added a commit that referenced this pull request May 5, 2021
* develop:
  feat: refactor msg template components; add telegram character limit (#1148)
  refactor: use shared function to initialize models (#1172)
  chore: setup scaffolding for backend tests (#940)
  1.23.0
  fix(frontend): fix frontend test flakiness (#1162)
  fix: update successful delivery status only if error does not exist (#1150)
  chore: upgrade dependencies (#1153)
  feat: add unit tests for error states in critical workflows (#1118)
  feat: support whitelisting domains through `agencies` table (#1141)
  feat: add tests for happy paths in critical workflows (#1110)
  fix: prevent campaign names from causing dashboard rows to overflow (#1147)
lamkeewei added a commit that referenced this pull request May 7, 2021
* develop:
  fix(backend): docker build and tsc output directory structure (#1177)
  feat: refactor msg template components; add telegram character limit (#1148)
lamkeewei added a commit that referenced this pull request May 10, 2021
* develop:
  fix: fix error when updating Telegram ID for an existing phone number (#1178)
  chore: upgrade React; use new JSX transform; sort imports (#1129)
  fix(backend): docker build and tsc output directory structure (#1177)
  feat: refactor msg template components; add telegram character limit (#1148)
  refactor: use shared function to initialize models (#1172)
  chore: setup scaffolding for backend tests (#940)
  1.23.0
  fix(frontend): fix frontend test flakiness (#1162)
  fix: update successful delivery status only if error does not exist (#1150)
  chore: upgrade dependencies (#1153)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants