Skip to content

Commit 9be0a5c

Browse files
committed
feat: handle external mail lists
1 parent 678dbb3 commit 9be0a5c

4 files changed

Lines changed: 84 additions & 27 deletions

File tree

src/i18n.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ i18n
5353
email: "E-posta",
5454
full_name: "Ad Soyad",
5555
actions: "İşlemler",
56+
external: "Harici",
57+
},
58+
warnings: {
59+
external_source: "Bu liste harici bir kaynaktan sağlanmaktadır. Düzenleme ve silme işlemleri devre dışıdır.",
5660
},
5761
},
5862
applications: {

src/pages/mailing-lists/edit.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { Edit, useForm } from "@refinedev/antd";
2+
import { useNavigation } from "@refinedev/core";
23
import { Form, Input } from "antd";
4+
import { useEffect } from "react";
35
import { useTranslation } from "react-i18next";
46

57
export const MailingListEdit = () => {
68
const { t } = useTranslation();
7-
const { formProps, saveButtonProps } = useForm({
9+
const { list } = useNavigation();
10+
const { formProps, saveButtonProps, query } = useForm({
811
resource: "mailing_lists"
912
});
1013

14+
const record = query?.data?.data;
15+
16+
useEffect(() => {
17+
if (record && record.source !== "internal") {
18+
list("mailing_lists");
19+
}
20+
}, [record]);
21+
1122
return (
1223
<Edit
1324
saveButtonProps={{ ...saveButtonProps, children: t("buttons.save") }}

src/pages/mailing-lists/list.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ShowButton,
77
useTable,
88
} from "@refinedev/antd";
9-
import { Space, Table } from "antd";
9+
import { Space, Table, Tag } from "antd";
1010
import { useTranslation } from "react-i18next";
1111

1212
export const MailingListList = () => {
@@ -24,20 +24,39 @@ export const MailingListList = () => {
2424
}>
2525
<Table {...tableProps} rowKey="id">
2626
<Table.Column dataIndex="id" title={t("mailing_lists.fields.id")} />
27-
<Table.Column dataIndex="name" title={t("mailing_lists.fields.name")} />
27+
<Table.Column
28+
dataIndex="name"
29+
title={t("mailing_lists.fields.name")}
30+
render={(value: string, record: any) => (
31+
<Space size="small">
32+
{value}
33+
{record.source !== "internal" && (
34+
<Tag color="orange">{t("mailing_lists.fields.external")}</Tag>
35+
)}
36+
</Space>
37+
)}
38+
/>
2839
<Table.Column
2940
dataIndex="created_at"
3041
title={t("mailing_lists.fields.created_at")}
31-
render={(value: string) => <DateField value={value} format="LLL" />}
42+
render={(value: string, record: any) =>
43+
record.source === "internal"
44+
? <DateField value={value} format="LLL" />
45+
: <span style={{ color: "rgba(0,0,0,0.25)" }}></span>
46+
}
3247
/>
3348
<Table.Column
3449
title={t("mailing_lists.fields.actions")}
3550
dataIndex="actions"
3651
render={(_, record: any) => (
3752
<Space>
38-
<EditButton hideText size="small" recordItemId={record.id} />
53+
{record.source === "internal" && (
54+
<EditButton hideText size="small" recordItemId={record.id} />
55+
)}
3956
<ShowButton hideText size="small" recordItemId={record.id} />
40-
<DeleteButton hideText size="small" recordItemId={record.id} />
57+
{record.source === "internal" && (
58+
<DeleteButton hideText size="small" recordItemId={record.id} />
59+
)}
4160
</Space>
4261
)}
4362
/>

src/pages/mailing-lists/show.tsx

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { DateField, Show, useModalForm, useTable } from "@refinedev/antd";
1+
import { DateField, DeleteButton, EditButton, RefreshButton, Show, useModalForm, useTable } from "@refinedev/antd";
22
import { useShow, useDelete } from "@refinedev/core";
3-
import { Typography, Card, Row, Col, Table, Button, Space, Modal, Form, Input } from "antd";
3+
import { Alert, Typography, Card, Row, Col, Table, Button, Space, Modal, Form, Input } from "antd";
44
import { useTranslation } from "react-i18next";
55
import { DeleteOutlined, PlusOutlined } from "@ant-design/icons";
66

@@ -46,6 +46,8 @@ export const MailingListShow = () => {
4646
});
4747
};
4848

49+
const isInternal = record?.source === "internal";
50+
4951
return (
5052
<Show
5153
isLoading={isLoading}
@@ -54,23 +56,40 @@ export const MailingListShow = () => {
5456
{t("mailing_lists.titles.show")}
5557
</span>
5658
}
59+
headerButtons={({ editButtonProps, deleteButtonProps, refreshButtonProps }) => (
60+
<>
61+
{isInternal && editButtonProps && <EditButton {...editButtonProps} />}
62+
{isInternal && deleteButtonProps && <DeleteButton {...deleteButtonProps} />}
63+
{refreshButtonProps && <RefreshButton {...refreshButtonProps} />}
64+
</>
65+
)}
5766
>
67+
{!isInternal && !isLoading && (
68+
<Alert
69+
type="warning"
70+
showIcon
71+
message={t("mailing_lists.warnings.external_source")}
72+
style={{ marginBottom: 16 }}
73+
/>
74+
)}
5875
<Row gutter={[16, 16]}>
5976
<Col span={24}>
6077
<Card size="small">
6178
<Row>
62-
<Col span={6}>
79+
<Col span={isInternal ? 6 : 8}>
6380
<Title level={5} style={{ margin: 0 }}>{t("mailing_lists.fields.id")}</Title>
6481
<Text>{record?.id}</Text>
6582
</Col>
66-
<Col span={12}>
83+
<Col span={isInternal ? 12 : 16}>
6784
<Title level={5} style={{ margin: 0 }}>{t("mailing_lists.fields.name")}</Title>
6885
<Text>{record?.name}</Text>
6986
</Col>
70-
<Col span={6}>
71-
<Title level={5} style={{ margin: 0 }}>{t("mailing_lists.fields.created_at")}</Title>
72-
<DateField value={record?.created_at} format="LLL"/>
73-
</Col>
87+
{isInternal && (
88+
<Col span={6}>
89+
<Title level={5} style={{ margin: 0 }}>{t("mailing_lists.fields.created_at")}</Title>
90+
<DateField value={record?.created_at} format="LLL"/>
91+
</Col>
92+
)}
7493
</Row>
7594
</Card>
7695
</Col>
@@ -82,13 +101,15 @@ export const MailingListShow = () => {
82101
</span>
83102
}
84103
extra={
85-
<Button
86-
type="primary"
87-
icon={<PlusOutlined/>}
88-
onClick={() => show()}
89-
>
90-
{t("mailing_lists.fields.add_recipient")}
91-
</Button>
104+
isInternal && (
105+
<Button
106+
type="primary"
107+
icon={<PlusOutlined/>}
108+
onClick={() => show()}
109+
>
110+
{t("mailing_lists.fields.add_recipient")}
111+
</Button>
112+
)
92113
}
93114
>
94115
<Table
@@ -103,12 +124,14 @@ export const MailingListShow = () => {
103124
dataIndex="actions"
104125
render={(_, record: any) => (
105126
<Space>
106-
<Button
107-
danger
108-
size="small"
109-
icon={<DeleteOutlined/>}
110-
onClick={() => handleDelete(record.id)}
111-
/>
127+
{isInternal && (
128+
<Button
129+
danger
130+
size="small"
131+
icon={<DeleteOutlined/>}
132+
onClick={() => handleDelete(record.id)}
133+
/>
134+
)}
112135
</Space>
113136
)}
114137
/>

0 commit comments

Comments
 (0)