Skip to content

Commit

Permalink
Merge pull request #517 from itsvick/merge-release-1.1.0-1.2.0
Browse files Browse the repository at this point in the history
Issue #PS-0000 merge: Merge release 1.1.0 into release-1.2.0
  • Loading branch information
itsvick authored Feb 14, 2025
2 parents b46f81d + 7c6d7c2 commit 1143609
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev-server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
echo "${{ secrets.DEV_ENV }}" > .env
ls -ltra
chmod +x deploy.sh
./deploy.sh ${{ env.BRANCH_NAME }}
./deploy.sh ${{ env.BRANCH_NAME }}
57 changes: 47 additions & 10 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@
"FOUNDATION_COURSE": "Foundation Course",
"MAIN_COURSE": "Main Course",
"CONTENT_CREATOR_REVIEWER": "Content Creator/Reviewer",
"SCTA":"State Content Team Associate",
"MANAGE_NOTIFICATION": "Manage Notification Templates",
"SCTA": "State Content Team Associate",
"WORKSPACE": "Workspace",
"MANAGE_NOTIFICATION": "Manage Notifications"
"MENTOR":"Mentor",
"MENTOR_LEADER":"Mentor Leader"
},
"FACILITATORS": {
"STATE": "State",
Expand All @@ -226,6 +228,24 @@
"LEARNER_UPDATED_SUCCESSFULLY": "Learner has been successfully updated!",
"EDIT_LEARNER": "Edit Learner"
},
"MENTORS": {
"SEARCHBAR_PLACEHOLDER": "Search mentors..",
"NEW_MENTOR": "New Mentor",
"FIRST_SELECT_REQUIRED_FIELDS": "First select required fields",
"MENTOR_CREATED_SUCCESSFULLY": "Mentor has been successfully created!",
"USER_CREDENTIALS_WILL_BE_SEND_SOON": "Mentor is created, credentials will be sent soon",
"MENTOR_UPDATED_SUCCESSFULLY": "Mentor has been successfully updated!",
"EDIT_MENTOR": "Edit Mentor"
},
"MENTOR_LEADERS": {
"SEARCHBAR_PLACEHOLDER": "Search mentor leaders..",
"NEW_MENTOR_LEADER": "New Mentor leaders",
"FIRST_SELECT_REQUIRED_FIELDS": "First select required fields",
"MENTOR_LEADER_CREATED_SUCCESSFULLY": "Mentor leader has been successfully created!",
"USER_CREDENTIALS_WILL_BE_SEND_SOON": "Mentor leader is created, credentials will be sent soon",
"MENTOR_LEADER_UPDATED_SUCCESSFULLY": "Mentor leader has been successfully updated!",
"EDIT_MENTOR_LEADER": "Edit Mentor leader"
},
"TEAM_LEADERS": {
"SEARCHBAR_PLACEHOLDER": "Search Team leaders..",
"NEW_TEAM_LEADER": "New Team Leader",
Expand Down Expand Up @@ -489,7 +509,12 @@
"ARCHIVED_LEARNERS": " Archived Learners",
"CODE": "Code",
"DISTRICT": "District",
"DOB":"Date of Birth"
"DOB":"Date of Birth",
"ID":"Id",
"TITLE":"Title",
"KEY":"Key",
"CONTEXT":"Context"

},
"WORKSPACE": {
"EDITOR_WORKSPACE": "Editor Workspace",
Expand Down Expand Up @@ -537,11 +562,23 @@
"CONTINUE_PROGRAM":"Do you want to continue or discard the changes?",
"DRAFTS":"Drafts",
"DISCARD_CHANGES":"Discard Changes"






}
},
"NOTIFICATION":{
"CONTEXT_TYPE":"Context Type",
"ADD_NOTIFICATION_TEMPLATE":"Add Notification Template",
"UPDATE_NOTIFICATION_TEMPLATE":"Update Notification Template",
"PLEASE_FILL_REQUIRED_FIELDS":"Please fill in at least one template with both subject and body.",
"TEMPLATE_ADDED_SUCCESS":"Template Added Successfully!",
"TEMPLATE_UPDATED_SUCCESS":"Template Updated Successfully!",
"UNPUBLISHED":"Unpublished",
"PUBLISHED":"Published",
"TEMPLATE":"Template",
"USE_SAMPLE_TEMPLATE":"Use Sample Template",
"PREVIEW":"Preview",
"RESET":"Reset",
"UPDATE_TEMPLATE":"Update Template",
"Add_TEMPLATE":"Add new Template",
"DELETE_TEMPLATE_ALERT":"Are you sure you want to delete this template?",
"TEMPLATE_DELETED_SUCCESS":"Template with id {{templateId}} deleted successfully"
}
}
57 changes: 32 additions & 25 deletions src/components/notification-templates/AddTemplateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import Loader from "../Loader";
import {
createNotificationTemplate,
TemplatePayload,
updateNotificationTemplate
} from "@/services/NotificationTemplateService";
import { useRouter } from "next/router";
import { QueryKeys } from "@/utils/app.constant";
import { useQueryClient } from "@tanstack/react-query";
import { INotificationTemplate } from "@/utils/Interfaces";

import { useTranslation } from 'next-i18next';
// Interface for Notification Type Details
interface NotificationTypeDetails {
subject?: string;
Expand Down Expand Up @@ -174,7 +175,7 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({
const [loading, setLoading] = useState(false);
const router = useRouter();
const queryClient = useQueryClient();

const { t } = useTranslation();
// Initialize react-hook-form with validation schema
const {
control,
Expand Down Expand Up @@ -210,22 +211,34 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({

const makeAPICall = async (payload: TemplatePayload) => {
setLoading(true);
try {
const response = await createNotificationTemplate(payload);
if (response?.responseCode === "Created") {
showToastMessage("Template Added Successfully!", "success");
queryClient.invalidateQueries({
try {
let response;
if (isUpdate) {
delete (payload as { key?: string }).key;
response = await updateNotificationTemplate(templateDetails?.actionId as number, payload);
} else {
response = await createNotificationTemplate(payload);
}

console.log("response", response);
if (response?.responseCode === 'Created') {
showToastMessage(t("NOTIFICATION.TEMPLATE_ADDED_SUCCESS"), "success");
} else if (response?.responseCode === "OK") {
showToastMessage(t("NOTIFICATION.TEMPLATE_UPDATED_SUCCESS"), "success");
} queryClient.invalidateQueries({
queryKey: [QueryKeys.GET_ALL_NOTIFICATION_TEMPLATE],
exact: false,
});
router.push("/notification-templates");
}
} catch (error) {
catch (error) {
console.error("Error in uploading data:", error);
} finally {
setLoading(false);
}
};

}


// Handle form submission
const onSubmit: SubmitHandler<NotificationFormData> = (data) => {
Expand All @@ -235,10 +248,7 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({
const isSmsFilled = data.sms.subject?.trim() && data.sms.body?.trim();

if (!isEmailFilled && !isPushFilled && !isSmsFilled) {
showToastMessage(
"Please fill in at least one template with both subject and body.",
"warning"
);
showToastMessage(t("NOTIFICATION.PLEASE_FILL_REQUIRED_FIELDS"), "warning");
return;
}

Expand Down Expand Up @@ -346,14 +356,14 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({
control={control}
render={({ field }) => (
<FormControl fullWidth error={!!errors.status}>
<InputLabel id="status-label">Status</InputLabel>
<InputLabel id="status-label">{t("FORM.STATUS")}</InputLabel>
<Select
{...field}
labelId="status-label"
label="Status"
>
<MenuItem value="unpublished">Unpublished</MenuItem>
<MenuItem value="published">Published</MenuItem>
<MenuItem value="unpublished">{t("NOTIFICATION.UNPUBLISHED")}</MenuItem>
<MenuItem value="published">{t("NOTIFICATION.PUBLISHED")}</MenuItem>
</Select>
{errors.status && (
<Typography color="error" variant="body2">
Expand All @@ -371,7 +381,7 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({
>
<Box sx={{ display: "flex", alignItems: "center" }}>
<Typography variant="h6" sx={{ flexGrow: 1 }}>
{template.name} Template
{template.name}{t("NOTIFICATION.TEMPLATE")}
</Typography>

{template.value === "email" && (
Expand All @@ -381,8 +391,7 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({
size="small"
onClick={applyEmailTemplate}
>
Use Sample Template
</Button>
{t("NOTIFICATION.USE_SAMPLE_TEMPLATE")} </Button>
{emailBody?.length > 0 && !preview && (
<Button
sx={{
Expand All @@ -395,8 +404,7 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({
size="small"
onClick={() => setPreview(true)}
>
Preview
</Button>
{t("NOTIFICATION.PREVIEW")} </Button>
)}
</>
)}
Expand Down Expand Up @@ -487,11 +495,10 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({
</Box>
<Box mt={4} display="flex" justifyContent="right" gap={2}>
<Button variant="outlined" onClick={handleReset}>
Reset
{t("NOTIFICATION.RESET")}
</Button>
<Button variant="contained" type="submit" color="primary">
{isUpdate ? "Update Template" : "Add new template"}
</Button>
{isUpdate ? t("NOTIFICATION.UPDATE_TEMPLATE") : t("NOTIFICATION.ADD_TEMPLATE")} </Button>
</Box>
</form>
</Box>
Expand All @@ -512,4 +519,4 @@ const AddTemplateForm: React.FC<TemplateDetailsProps> = ({
);
};

export default AddTemplateForm;
export default AddTemplateForm;
6 changes: 4 additions & 2 deletions src/components/notification-templates/TemplateTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const TemplateTable: React.FC<TemplateTableProps> = ({ searchKey = '', context }
const response = await deleteNotificationTemplate(templateId);
queryClient.invalidateQueries({ queryKey: [QueryKeys.GET_ALL_NOTIFICATION_TEMPLATE], exact: false });
console.log('Template deleted:', response);
showToastMessage(`Template with id ${templateId} deleted successfully`, 'success');
showToastMessage(t("NOTIFICATION.TEMPLATE_DELETED_SUCCESS", {
templateId: templateId,
}), 'success');

} catch (error) {
console.error('Error deleting template', error);
Expand Down Expand Up @@ -87,7 +89,7 @@ const TemplateTable: React.FC<TemplateTableProps> = ({ searchKey = '', context }
{
confirmationModalOpen &&
<ConfirmationModal
message={"Are you sure you want to delete this template?"}
message={t("NOTIFICATION.DELETE_TEMPLATE_ALERT")}
handleAction={() => deleteTemplate(templateToBeDeleted?.actionId)}
buttonNames={{ primary: t("COMMON.YES"), secondary: t("COMMON.CANCEL") }
}
Expand Down
14 changes: 7 additions & 7 deletions src/data/tableColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ export const getNotificationTableData = (t: any, isMobile: boolean, isArchived?:

const configs: ColumnConfig[] = [

{ key: 'actionId', titleKey: 'ID', dataType: DataType.Number, width: 50, },
{ key: 'title', titleKey: 'TITLE', dataType: DataType.String, width: 180, },
{ key: 'key', titleKey: 'KEY', dataType: DataType.String, width: 180, },
{ key: 'context', titleKey: 'CONTEXT', width: 100, },
{ key: 'status', titleKey: 'STATUS', width: 100, },
{ key: 'templateType', titleKey: 'TYPE', dataType: DataType.Object, width: 100, style: { textAlign: 'center' } },
{ key: 'actions', titleKey: 'ACTIONS', width: 120 }
{ key: 'actionId', titleKey: 'TABLE_TITLE.ID', dataType: DataType.Number, width: 50, },
{ key: 'title', titleKey: 'TABLE_TITLE.TITLE', dataType: DataType.String, width: 180, },
{ key: 'key', titleKey: 'TABLE_TITLE.KEY', dataType: DataType.String, width: 180, },
{ key: 'context', titleKey: 'TABLE_TITLE.CONTEXT', width: 100, },
{ key: 'status', titleKey: 'TABLE_TITLE.STATUS', width: 100, },
{ key: 'templateType', titleKey: 'TABLE_TITLE.TYPE', dataType: DataType.Object, width: 100, style: { textAlign: 'center' } },
{ key: 'actions', titleKey: 'TABLE_TITLE.ACTIONS', width: 120 }
];


Expand Down
8 changes: 6 additions & 2 deletions src/pages/notification-templates/create.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BackButtonWithLabel from "@/components/common/BackButtonWithLabel";
import AddTemplateForm from "@/components/notification-templates/AddTemplateForm";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import { Box, IconButton, Typography } from "@mui/material";
Expand All @@ -12,15 +13,18 @@ const CreateNotificationTemplate = () => {

return (
<>
<Box
{/* <Box
sx={{ display: "flex", alignItems: "center", mb: 2, mt: 2 }}
onClick={() => router.back()}
>
<IconButton>
<ArrowBackIcon />
</IconButton>
<Typography variant="h2">Add Notification Template</Typography>
</Box>
</Box> */}

<BackButtonWithLabel label={t('NOTIFICATION.ADD_NOTIFICATION_TEMPLATE')}
/>
<AddTemplateForm />
</>
);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/notification-templates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ const NotificationTemplate = () => {
>
{(
<FormControl sx={{ width: '15%' }}>
<InputLabel id="context-select-label">Context Type</InputLabel>
<InputLabel id="context-select-label"> {t('NOTIFICATION.CONTEXT_TYPE')}
</InputLabel>
<Select
labelId="context-select-label"
id="context-select"
Expand Down
4 changes: 3 additions & 1 deletion src/pages/notification-templates/update/[key].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { INotificationTemplate } from "@/utils/Interfaces";
import { useQuery } from "@tanstack/react-query";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { useRouter } from "next/router";
import { useTranslation } from 'next-i18next';

const UpdateTemplate: React.FC = () => {
const router = useRouter();
const { key } = router.query;
const { t } = useTranslation();

// Fetch data using TanStack Query
const { data: templateResponse = null, isLoading, isError, error } = useQuery({
Expand All @@ -33,7 +35,7 @@ const UpdateTemplate: React.FC = () => {

{templateResponse?.length > 0 ?
<>
<BackButtonWithLabel label={'Update Notification'} />
<BackButtonWithLabel label={ t('NOTIFICATION.UPDATE_NOTIFICATION_TEMPLATE')} />
<AddTemplateForm templateDetails={templateResponse[0] as INotificationTemplate} isUpdate={true} />
</>
: null}
Expand Down

0 comments on commit 1143609

Please sign in to comment.