Skip to content
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
38 changes: 21 additions & 17 deletions src/UI/components/email/composeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CheckBoxIcon from '@mui/icons-material/CheckBox';
import SendIcon from '@mui/icons-material/Send';
import { TextEditor } from '../shared/textEditor/RichTextEditor';
import { useUser } from '@auth0/nextjs-auth0/client';
import { useTranslations } from 'next-intl';

export interface UnifiedRecipient {
id: string;
Expand Down Expand Up @@ -53,6 +54,7 @@ export const ComposeMessageForm: React.FC<ComposeMessageFormProps> = ({
}) => {
const { user } = useUser();
const [subject, setSubject] = useState('');
const t = useTranslations('Email_Compose');
const [audienceMode, setAudienceMode] = useState<
'all' | 'subscribers' | 'users' | 'custom'
>('custom');
Expand Down Expand Up @@ -141,33 +143,35 @@ export const ComposeMessageForm: React.FC<ComposeMessageFormProps> = ({
color="primary"
sx={{ mb: 3, fontWeight: 600 }}
>
Compose Message
{t('title')}
</Typography>

<Box component="form" onSubmit={handleSubmit} noValidate>
<Stack spacing={3}>
<FormControl fullWidth disabled={loading}>
<InputLabel id="audience-mode-label">Recipient Group</InputLabel>
<InputLabel id="audience-mode-label">
{t('recipientGroup')}
</InputLabel>
<Select
labelId="audience-mode-label"
label="Recipient Group"
label={t('recipientGroup')}
value={audienceMode}
onChange={(e) => {
setAudienceMode(e.target.value as any);
setTouched((prev) => ({ ...prev, recipients: true }));
}}
>
<MenuItem value="custom">Custom(Users / Subscribers)</MenuItem>
<MenuItem value="all">Users & Subscribers</MenuItem>
<MenuItem value="subscribers">All Subscribers Only</MenuItem>
<MenuItem value="users">All Users Only</MenuItem>
<MenuItem value="custom">{t('groupCustom')}</MenuItem>
<MenuItem value="all">{t('groupAll')}</MenuItem>
<MenuItem value="subscribers">{t('groupSubscribers')}</MenuItem>
<MenuItem value="users">{t('groupUsers')}</MenuItem>
</Select>
</FormControl>

{audienceMode === 'custom' ? (
<Autocomplete
multiple
fullWidth // <--- Forces horizontal reach to 100%
fullWidth
limitTags={5}
disableCloseOnSelect
options={recipientsList}
Expand Down Expand Up @@ -226,14 +230,14 @@ export const ComposeMessageForm: React.FC<ComposeMessageFormProps> = ({
renderInput={(params) => (
<TextField
{...params}
fullWidth // <--- Forces the inner input's horizontal reach
label="Select Recipients *"
placeholder="Search by name, email, or role..."
fullWidth
label={t('selectRecipients')}
placeholder={t('searchPlaceholder')}
error={recipientsError}
helperText={
recipientsError
? 'Please select at least one valid recipient'
: 'Unsubscribed accounts and users with disabled notifications are grayed out.'
? t('recipientsError')
: t('customRecipientsHelper')
}
/>
)}
Expand All @@ -255,15 +259,15 @@ export const ComposeMessageForm: React.FC<ComposeMessageFormProps> = ({
)}

<TextField
label="Subject"
label={t('subject')}
fullWidth
required
disabled={loading}
value={subject}
onChange={(e) => setSubject(e.target.value)}
onBlur={() => setTouched((prev) => ({ ...prev, subject: true }))}
error={subjectError}
helperText={subjectError ? 'Subject cannot be empty' : ''}
helperText={subjectError ? t('subjectError') : ''}
/>

<Box>
Expand All @@ -279,7 +283,7 @@ export const ComposeMessageForm: React.FC<ComposeMessageFormProps> = ({
}
}}
error={messageError}
helperText={messageError ? 'Message cannot be empty' : ''}
helperText={messageError ? t('messageError') : ''}
/>
</Box>
{/*<Box sx={{ mt: 2 }}>
Expand Down Expand Up @@ -323,7 +327,7 @@ export const ComposeMessageForm: React.FC<ComposeMessageFormProps> = ({
startIcon={<SendIcon />}
disabled={!isFormValid || loading}
>
Send ({activeRecipientEmails.length})
{t('sendBtn', { count: activeRecipientEmails.length })}
</Button>
</Box>
</Stack>
Expand Down
2 changes: 1 addition & 1 deletion src/UI/components/shared/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function Footer() {
<Link href="/subscribe" passHref legacyBehavior>
<MuiLink
underline="hover"
sx={{ fontWeight: 600, color: 'primary.main' }}
sx={{ fontWeight: 300, color: 'primary.main' }}
>
{t('subscribe') || 'Subscribe to Updates'}
</MuiLink>
Expand Down
50 changes: 25 additions & 25 deletions src/UI/components/subscription/manage_subsriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface Subscriber {
}

export const SubscriptionList = () => {
const t = useTranslations('AdminPage');
const t = useTranslations('ManageSubscription');
const [subscribers, setSubscribers] = useState<Subscriber[]>([]);
const [loading, setLoading] = useState(false);
const token = useAppSelector((state) => state.auth.token);
Expand All @@ -50,7 +50,7 @@ export const SubscriptionList = () => {
await exportSubscriber(token.toString());
} catch (error) {
console.error('Failed to export subscribers', error);
alert('Failed to Download excel file. Please try again');
alert(t('exportError'));
} finally {
setExporting(false);
}
Expand Down Expand Up @@ -87,9 +87,7 @@ export const SubscriptionList = () => {

const handleUnsubscribe = async (subscriberRow: Subscriber) => {
if (
!window.confirm(
`Are you sure you want to unsubscribe ${subscriberRow.email}?`
)
!window.confirm(t('unsubscribeConfirm', { email: subscriberRow.email }))
) {
return;
}
Expand All @@ -107,13 +105,13 @@ export const SubscriptionList = () => {
fetchSubscribers();
} catch (error) {
console.error('Failed to unsubscribe user:', error);
alert('Failed to process unsubscription.');
alert(t('unsubscribeError'));
}
};

const handleAddSubscriber = async () => {
if (!newSub.email.trim()) {
setModalError('Email is required');
setModalError(t('emailRequired'));
return;
}

Expand All @@ -128,9 +126,7 @@ export const SubscriptionList = () => {
setOpenModal(false);
fetchSubscribers(); // Refresh the grid
} catch (error: any) {
setModalError(
error.response?.data?.message || 'Failed to add subscriber'
);
setModalError(error.response?.data?.message || t('addSubscriberError'));
} finally {
setSubmitting(false);
}
Expand All @@ -139,16 +135,16 @@ export const SubscriptionList = () => {
const columns: GridColDef[] = [
{
field: 'name',
headerName: 'Name',
headerName: t('columns.name'),
width: 200,
valueGetter: (params: any) =>
`${params.row.first_name || ''} ${params.row.last_name || ''}`.trim() ||
'N/A',
},
{ field: 'email', headerName: 'Email Address', width: 250 },
{ field: 'email', headerName: t('columns.email'), width: 250 },
{
field: 'account_status',
headerName: 'Status',
headerName: t('columns.status'),
width: 180,
renderCell: (params: GridRenderCellParams) => {
let color: 'default' | 'success' | 'error' | 'warning' = 'default';
Expand All @@ -172,13 +168,13 @@ export const SubscriptionList = () => {
},
{
field: 'notifications_enabled',
headerName: 'Notifications',
headerName: t('columns.notifications'),
width: 150,
type: 'boolean',
},
{
field: 'token_expires_at',
headerName: 'Token Expiry',
headerName: t('columns.tokenExpiry'),
type: 'dateTime',
width: 180,
valueGetter: (params: any) =>
Expand All @@ -194,7 +190,7 @@ export const SubscriptionList = () => {
},
{
field: 'actions',
headerName: 'Actions',
headerName: t('columns.actions'),
width: 100,
sortable: false,
filterable: false,
Expand All @@ -207,7 +203,11 @@ export const SubscriptionList = () => {
size="small"
disabled={isUnsubscribed}
onClick={() => handleUnsubscribe(params.row as Subscriber)}
title={isUnsubscribed ? 'Already unsubscribed' : 'Unsubscribe user'}
title={
isUnsubscribed
? t('tooltips.alreadyUnsubscribed')
: t('tooltips.unsubscribeUser')
}
>
<DeleteIcon />
</IconButton>
Expand All @@ -227,23 +227,23 @@ export const SubscriptionList = () => {
}}
>
<Typography variant="h5" color="primary">
Subscriber List
{t('subscriberListTitle')}
</Typography>
<Button
variant="outlined"
onClick={handleExport}
disabled={exporting}
sx={{ mr: 2 }}
>
{exporting ? 'Exporting...' : 'Export to Excel'}
{exporting ? t('exportingBtn') : t('exportBtn')}
</Button>

<Button
variant="contained"
startIcon={<AddIcon />}
onClick={() => setOpenModal(true)}
>
Add Subscriber
{t('addSubscriberBtn')}
</Button>
</Box>

Expand All @@ -268,7 +268,7 @@ export const SubscriptionList = () => {
<DialogContent>
<TextField
margin="dense"
label="First Name"
label={t('dialog.firstName')}
fullWidth
value={newSub.first_name}
onChange={(e) =>
Expand All @@ -278,7 +278,7 @@ export const SubscriptionList = () => {
/>
<TextField
margin="dense"
label="Last Name"
label={t('dialog.lastName')}
fullWidth
value={newSub.last_name}
onChange={(e) =>
Expand All @@ -288,7 +288,7 @@ export const SubscriptionList = () => {
/>
<TextField
margin="dense"
label="Email Address *"
label={t('dialog.emailLabel')}
type="email"
fullWidth
required
Expand All @@ -301,14 +301,14 @@ export const SubscriptionList = () => {
</DialogContent>
<DialogActions>
<Button onClick={() => setOpenModal(false)} disabled={submitting}>
Cancel
{t('dialog.cancel')}
</Button>
<Button
onClick={handleAddSubscriber}
variant="contained"
disabled={submitting || !newSub.email.trim()}
>
{submitting ? <CircularProgress size={24} /> : 'Add User'}
{submitting ? <CircularProgress size={24} /> : t('dialog.addUser')}
</Button>
</DialogActions>
</Dialog>
Expand Down
Loading
Loading