Skip to content

Commit

Permalink
fix: pass saveTemplate as a prop to BodyTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
zwliew committed May 3, 2021
1 parent b4ffb91 commit fecd93c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
StepSection,
} from 'components/common'
import SaveDraftModal from 'components/dashboard/create/save-draft-modal'
import { saveTemplate } from 'services/sms.service'

import type { Dispatch, SetStateAction } from 'react'

Expand All @@ -22,12 +21,20 @@ function BodyTemplate({
setActiveStep,
warnCharacterCount,
errorCharacterCount,
saveTemplate,
}: {
setActiveStep:
| Dispatch<SetStateAction<SMSProgress>>
| Dispatch<SetStateAction<TelegramProgress>>
warnCharacterCount: number
errorCharacterCount: number
saveTemplate: (
campaignId: number,
body: string
) => Promise<{
numRecipients: number
updatedTemplate?: { body: string; params: string[] }
}>
}) {
const { campaign, updateCampaign } = useContext(CampaignContext)
const { setFinishLaterContent } = useContext(FinishLaterModalContext)
Expand Down Expand Up @@ -79,7 +86,7 @@ function BodyTemplate({
} catch (err) {
setErrorMsg(err.message)
}
}, [body, campaignId, setActiveStep, updateCampaign])
}, [body, campaignId, setActiveStep, updateCampaign, saveTemplate])

// Set callback for finish later button
useEffect(() => {
Expand All @@ -101,7 +108,7 @@ function BodyTemplate({
return () => {
setFinishLaterContent(null)
}
}, [body, campaignId, setFinishLaterContent])
}, [body, campaignId, setFinishLaterContent, saveTemplate])

function replaceNewLines(body: string): string {
return (body || '').replace(/<br\s*\/?>/g, '\n')
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/dashboard/create/sms/SMSCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import styles from '../Create.module.scss'
import {
SMS_WARN_EXCEED_CHARACTER_THRESHOLD,
SMS_ERROR_EXCEED_CHARACTER_THRESHOLD,
saveTemplate,
} from 'services/sms.service'

const SMS_PROGRESS_STEPS = [
Expand Down Expand Up @@ -45,6 +46,7 @@ const CreateSMS = () => {
setActiveStep={setActiveStep}
warnCharacterCount={SMS_WARN_EXCEED_CHARACTER_THRESHOLD}
errorCharacterCount={SMS_ERROR_EXCEED_CHARACTER_THRESHOLD}
saveTemplate={saveTemplate}
/>
)
case SMSProgress.UploadRecipients:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import styles from '../Create.module.scss'
import {
TELEGRAM_WARN_EXCEED_CHARACTER_THRESHOLD,
TELEGRAM_ERROR_EXCEED_CHARACTER_THRESHOLD,
saveTemplate,
} from 'services/telegram.service'

const TELEGRAM_PROGRESS_STEPS = [
Expand Down Expand Up @@ -43,6 +44,7 @@ const CreateTelegram = () => {
setActiveStep={setActiveStep}
warnCharacterCount={TELEGRAM_WARN_EXCEED_CHARACTER_THRESHOLD}
errorCharacterCount={TELEGRAM_ERROR_EXCEED_CHARACTER_THRESHOLD}
saveTemplate={saveTemplate}
/>
)
case TelegramProgress.UploadRecipients:
Expand Down

0 comments on commit fecd93c

Please sign in to comment.