-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathcrudDelete.ts
107 lines (101 loc) · 2.86 KB
/
crudDelete.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { Identifier, Record } from '../../types';
import { DELETE } from '../../dataFetchActions';
import { FETCH_END, FETCH_ERROR } from '../fetchActions';
import {
NotificationSideEffect,
RedirectionSideEffect,
RefreshSideEffect,
} from '../../sideEffect';
export const crudDelete = (
resource: string,
id: Identifier,
previousData: Record,
basePath: string,
redirectTo: RedirectionSideEffect = 'list',
refresh: RefreshSideEffect = true
): CrudDeleteAction => ({
type: CRUD_DELETE,
payload: { id, previousData },
meta: {
resource,
fetch: DELETE,
onSuccess: {
notification: {
body: 'ra.notification.deleted',
level: 'info',
messageArgs: {
smart_count: 1,
},
},
refresh,
redirectTo,
basePath,
},
onFailure: {
notification: {
body: 'ra.notification.http_error',
level: 'warning',
},
},
},
});
interface RequestPayload {
id: Identifier;
previousData: Record;
}
export const CRUD_DELETE = 'RA/CRUD_DELETE';
export interface CrudDeleteAction {
readonly type: typeof CRUD_DELETE;
readonly payload: RequestPayload;
readonly meta: {
resource: string;
fetch: typeof DELETE;
onSuccess: {
notification: NotificationSideEffect;
redirectTo: RedirectionSideEffect;
refresh: RefreshSideEffect;
basePath: string;
};
onFailure: {
notification: NotificationSideEffect;
};
};
}
export const CRUD_DELETE_LOADING = 'RA/CRUD_DELETE_LOADING';
export interface CrudDeleteLoadingAction {
readonly type: typeof CRUD_DELETE_LOADING;
readonly payload: RequestPayload;
readonly meta: {
resource: string;
};
}
export const CRUD_DELETE_FAILURE = 'RA/CRUD_DELETE_FAILURE';
export interface CrudDeleteFailureAction {
readonly type: typeof CRUD_DELETE_FAILURE;
readonly error: string | object;
readonly payload: string;
readonly requestPayload: RequestPayload;
readonly meta: {
resource: string;
notification: NotificationSideEffect;
fetchResponse: typeof CRUD_DELETE;
fetchStatus: typeof FETCH_ERROR;
};
}
export const CRUD_DELETE_SUCCESS = 'RA/CRUD_DELETE_SUCCESS';
export interface CrudDeleteSuccessAction {
readonly type: typeof CRUD_DELETE_SUCCESS;
readonly payload: {
data: Record;
};
readonly requestPayload: RequestPayload;
readonly meta: {
resource: string;
notification: NotificationSideEffect;
redirectTo: RedirectionSideEffect;
refresh: RefreshSideEffect;
basePath: string;
fetchResponse: typeof CRUD_DELETE;
fetchStatus: typeof FETCH_END;
};
}