Skip to content

Commit e602841

Browse files
committed
Auto save email filter on input field blur
1 parent 9ae9a57 commit e602841

15 files changed

Lines changed: 40 additions & 1052 deletions

File tree

apps/web/app/(with-contexts)/dashboard/(sidebar)/mails/broadcast/[id]/page.tsx

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { BROADCASTS } from "@ui-config/strings";
77
import { useContext } from "react";
88
import { PaperPlane, Clock } from "@courselit/icons";
99
import {
10-
Button,
1110
Form,
1211
FormField,
1312
Dialog2,
@@ -48,6 +47,7 @@ import { useSequence } from "@/hooks/use-sequence";
4847
import { useGraphQLFetch } from "@/hooks/use-graphql-fetch";
4948
import FilterContainer from "@components/admin/users/filter-container";
5049
import EmailViewer from "@components/admin/mails/email-viewer";
50+
import { Button } from "@components/ui/button";
5151

5252
const breadcrumbs = [
5353
{ label: BROADCASTS, href: "/dashboard/mails?tab=Broadcasts" },
@@ -63,6 +63,7 @@ export default function Page({
6363
}) {
6464
const address = useContext(AddressContext);
6565
const { id } = params;
66+
const { sequence, loading, error, loadSequence } = useSequence();
6667
const [filters, setFilters] = useState<UserFilter[]>([]);
6768
const [filtersAggregator, setFiltersAggregator] =
6869
useState<UserFilterAggregator>("or");
@@ -77,9 +78,6 @@ export default function Page({
7778
const [report, setReport] = useState<SequenceReport>();
7879
const [status, setStatus] = useState<SequenceStatus | null>(null);
7980

80-
// Use the sequence hook
81-
const { sequence, loading, error, loadSequence } = useSequence();
82-
8381
// Refs to track initial values and prevent saving during load
8482
const initialValues = useRef({
8583
subject: "",
@@ -140,7 +138,6 @@ export default function Page({
140138
}
141139
}, [error, toast]);
142140

143-
// Debounced save function
144141
const debouncedSave = useCallback(async () => {
145142
if (!emailId || isInitialLoad.current) {
146143
return;
@@ -248,7 +245,7 @@ export default function Page({
248245
};
249246
} catch (e: any) {
250247
toast({
251-
title: `${TOAST_TITLE_ERROR}: ${e.message}`,
248+
title: TOAST_TITLE_ERROR,
252249
description: e.message,
253250
variant: "destructive",
254251
});
@@ -285,7 +282,7 @@ export default function Page({
285282

286283
if (!subject.trim()) {
287284
toast({
288-
title: `${TOAST_TITLE_ERROR}: ${ERROR_SUBJECT_EMPTY}`,
285+
title: TOAST_TITLE_ERROR,
289286
description: ERROR_SUBJECT_EMPTY,
290287
variant: "destructive",
291288
});
@@ -295,7 +292,7 @@ export default function Page({
295292

296293
if (sendLater && delay === 0) {
297294
toast({
298-
title: `${TOAST_TITLE_ERROR}: ${ERROR_DELAY_EMPTY}`,
295+
title: TOAST_TITLE_ERROR,
299296
description: ERROR_DELAY_EMPTY,
300297
variant: "destructive",
301298
});
@@ -388,7 +385,7 @@ export default function Page({
388385
}
389386
} catch (e: any) {
390387
toast({
391-
title: `${TOAST_TITLE_ERROR}: ${e.message}`,
388+
title: TOAST_TITLE_ERROR,
392389
description: e.message,
393390
variant: "destructive",
394391
});
@@ -461,7 +458,7 @@ export default function Page({
461458
}
462459
} catch (e: any) {
463460
toast({
464-
title: `${TOAST_TITLE_ERROR}: ${e.message}`,
461+
title: TOAST_TITLE_ERROR,
465462
description: e.message,
466463
variant: "destructive",
467464
});
@@ -512,12 +509,14 @@ export default function Page({
512509
</div>
513510
<fieldset>
514511
<label className="mb-1 font-medium">To</label>
515-
<FilterContainer
516-
filter={{ aggregator: filtersAggregator, filters }}
517-
onChange={onFilterChange}
518-
disabled={!isEditable}
519-
address={address}
520-
/>
512+
{!isInitialLoad.current && (
513+
<FilterContainer
514+
filter={{ aggregator: filtersAggregator, filters }}
515+
onChange={onFilterChange}
516+
disabled={!isEditable}
517+
address={address}
518+
/>
519+
)}
521520
</fieldset>
522521
<Form className="flex flex-col gap-4" onSubmit={onSubmit}>
523522
<FormField
@@ -528,25 +527,6 @@ export default function Page({
528527
setSubject(e.target.value)
529528
}
530529
/>
531-
{/* {isEditable && (
532-
<div>
533-
<Button
534-
variant="outline"
535-
size="sm"
536-
className="gap-2"
537-
onClick={(e) => {
538-
e.preventDefault();
539-
}}
540-
href={`/dashboard/mail/${id}/${emailId}?redirectTo=/dashboard/mails/broadcast/${id}`}
541-
component="link"
542-
>
543-
<span className="flex items-center gap-2">
544-
<Edit className="h-4 w-4" />
545-
Edit Email
546-
</span>
547-
</Button>
548-
</div>
549-
)} */}
550530
<EmailViewer
551531
content={content}
552532
emailEditorLink={

apps/web/components/admin/users/filter-container/filter-editor/categories-map.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

apps/web/components/admin/users/filter-container/filter-editor/community.tsx

Lines changed: 0 additions & 103 deletions
This file was deleted.

apps/web/components/admin/users/filter-container/filter-editor/email.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)