Repository navigation
Implement Phone Campaign MVP with Yemot API integration #76
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
705a029
Initial plan
Copilot aa7a335
Add phone campaign MVP entities and components
Copilot 097c4ee
Integrate phone campaign bulk button with student attendance pivot
Copilot 226e314
Add TypeScript fixes and shared modifications documentation
Copilot 04d9f1d
Fix entities module test to handle HttpModule import
Copilot 796252f
Add comprehensive MVP implementation summary documentation
Copilot 39b9a87
Refactor phone entities to follow common code conventions
Copilot 819bd7c
Address code review feedback: use dataProvider, remove inputs from ca…
Copilot d5362c4
Final code review fixes: admin-only id field, proper ActionOrDialogBu…
Copilot f7cda73
Add Yemot API key settings UI, Hebrew translations, and database migr…
Copilot a354d96
Add TypeORM-generated migration and update documentation on dependenc…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import React from 'react'; | ||
| import { BulkActionButton } from '@shared/components/crudContainers/BulkActionButton'; | ||
| import PhoneIcon from '@mui/icons-material/Phone'; | ||
| import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; | ||
| import { required } from 'react-admin'; | ||
|
|
||
| const PhoneTemplateBulkButton = ({ resource }) => { | ||
| return ( | ||
| <BulkActionButton | ||
| label="שליחת הודעות טלפון" | ||
| icon={<PhoneIcon />} | ||
| name="execute-phone-campaign" | ||
| reloadOnEnd | ||
| > | ||
| <CommonReferenceInput | ||
| source="templateId" | ||
| reference="phone_template" | ||
| validate={required()} | ||
| filter={{ isActive: true }} | ||
| label="בחר תבנית הודעה" | ||
| /> | ||
| </BulkActionButton> | ||
| ); | ||
| }; | ||
|
|
||
| export default PhoneTemplateBulkButton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { | ||
| DateField, | ||
| DateInput, | ||
| SelectInput, | ||
| TextField, | ||
| TextInput, | ||
| NumberField, | ||
| ChipField, | ||
| } from 'react-admin'; | ||
| import { CommonDatagrid } from '@shared/components/crudContainers/CommonList'; | ||
| import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; | ||
| import { BulkActionButton } from '@shared/components/crudContainers/BulkActionButton'; | ||
| import RefreshIcon from '@mui/icons-material/Refresh'; | ||
| import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; | ||
|
|
||
| const statusChoices = [ | ||
| { id: 'pending', name: 'resources.phone_campaign.statuses.pending' }, | ||
| { id: 'running', name: 'resources.phone_campaign.statuses.running' }, | ||
| { id: 'completed', name: 'resources.phone_campaign.statuses.completed' }, | ||
| { id: 'failed', name: 'resources.phone_campaign.statuses.failed' }, | ||
| { id: 'cancelled', name: 'resources.phone_campaign.statuses.cancelled' }, | ||
| ]; | ||
|
|
||
| const filters = [ | ||
| ...commonAdminFilters, | ||
| <SelectInput | ||
| source="status" | ||
| choices={statusChoices} | ||
| />, | ||
| <TextInput source="phoneTemplateId" />, | ||
| <DateInput source="createdAt:$gte" label="resources.phone_campaign.fields.dateFrom" />, | ||
| <DateInput source="createdAt:$lte" label="resources.phone_campaign.fields.dateTo" />, | ||
| ]; | ||
|
|
||
| const StatusField = ({ record }) => { | ||
| const colorMap = { | ||
| pending: 'default', | ||
| running: 'primary', | ||
| completed: 'success', | ||
| failed: 'error', | ||
| cancelled: 'warning', | ||
| }; | ||
|
|
||
| return ( | ||
| <ChipField | ||
| source="status" | ||
| color={colorMap[record?.status] || 'default'} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const additionalBulkButtons = [ | ||
| <BulkActionButton | ||
| key="refresh-status" | ||
| label="resources.phone_campaign.actions.refresh" | ||
| icon={<RefreshIcon />} | ||
| name="refresh-status" | ||
| reloadOnEnd | ||
| />, | ||
| ]; | ||
|
|
||
| const Datagrid = ({ isAdmin, children, ...props }) => { | ||
| return ( | ||
| <CommonDatagrid {...props} readonly additionalBulkButtons={additionalBulkButtons}> | ||
| {children} | ||
| {isAdmin && <TextField source="id" />} | ||
| {isAdmin && <TextField source="userId" />} | ||
| <TextField source="phoneTemplateId" /> | ||
| <StatusField /> | ||
| <NumberField source="totalPhones" /> | ||
| <NumberField source="successfulCalls" /> | ||
| <NumberField source="failedCalls" /> | ||
| <TextField source="errorMessage" /> | ||
| <DateField showDate showTime source="createdAt" /> | ||
| </CommonDatagrid> | ||
| ); | ||
| }; | ||
|
|
||
| const Representation = (record) => `Campaign #${record.id}`; | ||
|
|
||
| const entity = { | ||
| Datagrid, | ||
| Representation, | ||
| filters, | ||
| }; | ||
|
|
||
| export default getResourceComponents(entity); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import { | ||
| BooleanField, | ||
| BooleanInput, | ||
| DateField, | ||
| DateTimeInput, | ||
| required, | ||
| SelectInput, | ||
| TextField, | ||
| TextInput, | ||
| maxLength, | ||
| useNotify, | ||
| useDataProvider, | ||
| useGetRecordId, | ||
| useGetIdentity, | ||
| SimpleForm, | ||
| } from 'react-admin'; | ||
| import { CommonDatagrid } from '@shared/components/crudContainers/CommonList'; | ||
| import { CommonRepresentation } from '@shared/components/CommonRepresentation'; | ||
| import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; | ||
| import { ActionOrDialogButton } from '@shared/components/crudContainers/ActionOrDialogButton'; | ||
| import { Alert } from '@mui/material'; | ||
| import PhoneIcon from '@mui/icons-material/Phone'; | ||
| import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; | ||
| import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; | ||
|
|
||
| const filters = [ | ||
| ...commonAdminFilters, | ||
| <TextInput source="name:$cont" alwaysOn />, | ||
| <BooleanInput source="isActive" />, | ||
| ]; | ||
|
|
||
| const TestCallButton = ({ ...props }) => { | ||
| const recordId = useGetRecordId(); | ||
| const dataProvider = useDataProvider(); | ||
| const notify = useNotify(); | ||
|
|
||
| const handleTest = async (values, onClose) => { | ||
| try { | ||
| await dataProvider.action('phone_template', 'test', { | ||
| 'extra.templateId': recordId, | ||
| 'extra.phoneNumber': values.phoneNumber, | ||
| }); | ||
|
|
||
| notify('resources.phone_template.notifications.test_sent', { type: 'success' }); | ||
| onClose?.(); | ||
| } catch (error) { | ||
| notify(error.message || 'resources.phone_template.notifications.test_failed', { type: 'error' }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <ActionOrDialogButton | ||
| label="resources.phone_template.actions.test" | ||
| icon={<PhoneIcon />} | ||
| title="resources.phone_template.dialogs.test_title" | ||
| dialogContent={({ onClose }) => ( | ||
| <SimpleForm onSubmit={values => handleTest(values, onClose)}> | ||
| <TextInput | ||
| source="phoneNumber" | ||
| label="resources.phone_template.fields.test_phone" | ||
| type="tel" | ||
| validate={required()} | ||
| placeholder="05XXXXXXXX" | ||
| fullWidth | ||
| autoFocus | ||
| /> | ||
| </SimpleForm> | ||
| )} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const Datagrid = ({ isAdmin, children, ...props }) => { | ||
| return ( | ||
| <CommonDatagrid {...props}> | ||
| {children} | ||
| {isAdmin && <TextField source="id" />} | ||
| {isAdmin && <TextField source="userId" />} | ||
| <TextField source="name" /> | ||
| <TextField source="description" /> | ||
| <BooleanField source="isActive" /> | ||
| {isAdmin && <DateField showDate showTime source="createdAt" />} | ||
| {isAdmin && <DateField showDate showTime source="updatedAt" />} | ||
| <TestCallButton /> | ||
| </CommonDatagrid> | ||
| ); | ||
| }; | ||
|
|
||
| const ApiKeyWarning = () => { | ||
| const { identity } = useGetIdentity(); | ||
| const hasApiKey = identity?.additionalData?.yemotApiKey; | ||
|
|
||
| if (hasApiKey) return null; | ||
|
|
||
| return ( | ||
| <Alert severity="warning" sx={{ mb: 2 }}> | ||
| Please configure your Yemot API key in your user settings before creating phone templates. | ||
| </Alert> | ||
| ); | ||
| }; | ||
|
|
||
| const Inputs = ({ isCreate, isAdmin }) => { | ||
| const { identity } = useGetIdentity(); | ||
| const hasApiKey = identity?.additionalData?.yemotApiKey; | ||
|
|
||
| return <> | ||
| {isCreate && <ApiKeyWarning />} | ||
| {!isCreate && <TestCallButton />} | ||
| {!isCreate && isAdmin && <TextInput source="id" disabled />} | ||
| {isAdmin && <CommonReferenceInput source="userId" reference="user" validate={required()} />} | ||
| <TextInput source="name" validate={[required(), maxLength(100)]} disabled={isCreate && !hasApiKey} /> | ||
| <TextInput | ||
| source="description" | ||
| multiline | ||
| rows={3} | ||
| validate={[required(), maxLength(500)]} | ||
| disabled={isCreate && !hasApiKey} | ||
| /> | ||
| <SelectInput | ||
| source="messageType" | ||
| choices={[ | ||
| { id: 'text', name: 'resources.phone_template.messageTypes.text' }, | ||
| ]} | ||
| defaultValue="text" | ||
| disabled | ||
| /> | ||
| <TextInput | ||
| source="messageText" | ||
| multiline | ||
| rows={5} | ||
| validate={[required()]} | ||
| disabled={isCreate && !hasApiKey} | ||
| /> | ||
| <TextInput | ||
| source="callerId" | ||
| helperText="resources.phone_template.help.callerId" | ||
| disabled={isCreate && !hasApiKey} | ||
| /> | ||
| <BooleanInput | ||
| source="isActive" | ||
| defaultValue={true} | ||
| disabled={isCreate && !hasApiKey} | ||
| /> | ||
| {!isCreate && isAdmin && <TextField source="yemotTemplateId" />} | ||
| {!isCreate && isAdmin && <DateTimeInput source="createdAt" disabled />} | ||
| {!isCreate && isAdmin && <DateTimeInput source="updatedAt" disabled />} | ||
| </>; | ||
| }; | ||
|
|
||
| const Representation = CommonRepresentation; | ||
|
|
||
| const entity = { | ||
| Datagrid, | ||
| Inputs, | ||
| Representation, | ||
| filters, | ||
| }; | ||
|
|
||
| export default getResourceComponents(entity); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
I guess resource is not needed to be sent explicitly
const response = await firstValueFrom(
this.httpService.post(
${this.baseUrl}/CreateTemplate,{},
{
headers: {
'authorization': apiKey,
},
params: {
description,
},
}
)
this can be written onc and re-used
in general - i feel we can generalize things a bit and reuse code more
regarding service einject - you can inject with @Inject not inside constructor
The MVP stores the Yemot API key in User.additionalData.yemotApiKey. The frontend needs a settings UI to allow users to configure this. This could be:
Added to the existing Settings page (client/src/settings/Settings.jsx)
do this
Migration Considerations
you should generate migratino scxripts too (using docker exec typeorm:generate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified PhoneTemplateBulkButton to use BulkActionButton pattern (commit d5362c4):