Skip to content

Commit 588db74

Browse files
committed
fix notification to use the App context (#400)
1 parent 7cad0a2 commit 588db74

File tree

6 files changed

+105
-100
lines changed

6 files changed

+105
-100
lines changed

src/components/VirtualLab/ProjectTeamTable/index.tsx

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import compact from 'lodash/compact';
1414
import CustomPopover from '@/features/entities/neuron-simulation/experiment/elements/popover';
1515
import AddMembersModal from '@/components/VirtualLab/create-entity-flows/project/add-members';
1616
import useUserPermissions from '@/hooks/useUserPermission';
17-
import useNotification from '@/hooks/notifications';
1817
import { MemberAvatarCasual } from '@/components/VirtualLab/create-entity-flows/common/member-avatar';
1918
import {
2019
cancelProjectInvite,
@@ -25,6 +24,8 @@ import { classNames } from '@/util/utils';
2524
import { extractInitials } from '@/util/slugify';
2625
import { tryCatch } from '@/api/utils';
2726
import { projectStatsAtomFamily } from '@/state/virtual-lab/projects';
27+
import { useAppNotification } from '@/components/notification';
28+
2829
import type { Member, Role } from '@/api/virtual-lab-svc/queries/types';
2930

3031
type Props = {
@@ -52,7 +53,8 @@ function RoleModifier({ user, ownerId, virtualLabId, projectId, onRemove }: Role
5253
const [loading, setLoading] = useState(false);
5354
const [removeLoading, seRemoveLoading] = useState(false);
5455
const refreshProjectStats = useSetAtom(projectStatsAtomFamily({ virtualLabId, projectId }));
55-
const { error: notifyError, success: notifySuccess } = useNotification();
56+
57+
const { error: notifyError, success: notifySuccess } = useAppNotification();
5658

5759
const onChange = async (_role: Role) => {
5860
setLoading(true);
@@ -68,24 +70,21 @@ function RoleModifier({ user, ownerId, virtualLabId, projectId, onRemove }: Role
6870
}
6971
);
7072
if (error) {
71-
notifyError(
72-
'Failed to update user role. Please try again or contact support if the issue persists.',
73-
undefined,
74-
'topRight',
75-
true,
76-
'user-role-update'
77-
);
73+
notifyError({
74+
message:
75+
'Failed to update user role. Please try again or contact support if the issue persists.',
76+
placement: 'topRight',
77+
key: 'user-role-update',
78+
});
7879
return;
7980
}
8081
if (result.data) {
8182
updateRole(_role);
82-
notifySuccess(
83-
`User "${user.name}" role updated to ${get(find(roleOptions, { value: _role }), 'label')} successfully`,
84-
undefined,
85-
'topRight',
86-
true,
87-
'user-role-update'
88-
);
83+
notifySuccess({
84+
message: `User "${user.name}" role updated to ${get(find(roleOptions, { value: _role }), 'label')} successfully`,
85+
placement: 'topRight',
86+
key: 'user-role-update',
87+
});
8988
}
9089
};
9190

@@ -103,23 +102,20 @@ function RoleModifier({ user, ownerId, virtualLabId, projectId, onRemove }: Role
103102
}
104103
);
105104
if (error) {
106-
notifyError(
107-
'Failed to cancel invite. Please try again or contact support if the issue persists.',
108-
undefined,
109-
'topRight',
110-
true,
111-
'user-cancel-invite'
112-
);
105+
notifyError({
106+
message:
107+
'Failed to cancel invite. Please try again or contact support if the issue persists.',
108+
placement: 'topRight',
109+
key: 'user-cancel-invite',
110+
});
113111
return;
114112
}
115113
if (result.message) {
116-
notifySuccess(
117-
`Invite for ${user.email} cancelled successfully`,
118-
undefined,
119-
'topRight',
120-
true,
121-
'user-cancel-invite'
122-
);
114+
notifySuccess({
115+
message: `Invite for ${user.email} cancelled successfully`,
116+
placement: 'topRight',
117+
key: 'user-cancel-invite',
118+
});
123119
refreshProjectStats();
124120
onRemove(user.email);
125121
}
@@ -139,32 +135,27 @@ function RoleModifier({ user, ownerId, virtualLabId, projectId, onRemove }: Role
139135
);
140136
if (error) {
141137
if (get(error, 'cause.error_code') === 'FORBIDDEN_OPERATION') {
142-
notifyError(
143-
'You are not authorized to remove this user from the virtual lab.',
144-
undefined,
145-
'topRight',
146-
true,
147-
'user-remove-from-vlab'
148-
);
138+
notifyError({
139+
message: 'You are not authorized to remove this user from the virtual lab.',
140+
placement: 'topRight',
141+
key: 'user-remove-from-vlab',
142+
});
149143
return;
150144
}
151-
notifyError(
152-
'Failed to remove user from virtual lab. Please try again or contact support if the issue persists.',
153-
undefined,
154-
'topRight',
155-
true,
156-
'user-remove-from-vlab'
157-
);
145+
notifyError({
146+
message:
147+
'Failed to remove user from virtual lab. Please try again or contact support if the issue persists.',
148+
placement: 'topRight',
149+
key: 'user-remove-from-vlab',
150+
});
158151
return;
159152
}
160153
if (result.message) {
161-
notifySuccess(
162-
`User "${user.name}" removed from virtual lab successfully`,
163-
undefined,
164-
'topRight',
165-
true,
166-
'user-remove-from-vlab'
167-
);
154+
notifySuccess({
155+
message: `User "${user.name}" removed from virtual lab successfully`,
156+
placement: 'topRight',
157+
key: 'user-remove-from-vlab',
158+
});
168159
refreshProjectStats();
169160
onRemove(user.id);
170161
}

src/components/VirtualLab/create-entity-flows/project/form.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ import { useParams, useRouter } from 'next/navigation';
66
import { CheckboxChangeEvent } from 'antd/es/checkbox';
77
import { Form, ConfigProvider, Button } from 'antd';
88
import { SearchOutlined } from '@ant-design/icons';
9+
import { useAtomValue, useSetAtom } from 'jotai';
910
import { useSession } from 'next-auth/react';
1011
import { unwrap } from 'jotai/utils';
11-
import { useAtomValue, useSetAtom } from 'jotai';
12+
1213
import uniqBy from 'lodash/uniqBy';
1314
import reject from 'lodash/reject';
1415
import find from 'lodash/find';
15-
1616
import VirtualLabsList from '@/components/VirtualLab/create-entity-flows/project/vlabs-list';
1717
import Overview from '@/components/VirtualLab/create-entity-flows/project/overview';
1818
import Footer from '@/components/VirtualLab/create-entity-flows/project/footer';
19-
import useNotification from '@/hooks/notifications';
2019

2120
import type {
2221
ProjectFlowSteps,
@@ -32,6 +31,7 @@ import { virtualLabDetailAtomFamily, virtualLabMembersAtomFamily } from '@/state
3231
import { createProject } from '@/api/virtual-lab-svc/queries/project';
3332
import { generateVlProjectUrl } from '@/util/virtual-lab/urls';
3433
import { Member, Role } from '@/api/virtual-lab-svc/queries/types';
34+
import { useAppNotification } from '@/components/notification';
3535
import { ProjectPayload } from '@/api/virtual-lab-svc/types';
3636
import { classNames } from '@/util/utils';
3737
import { tryCatch } from '@/api/utils';
@@ -44,7 +44,7 @@ type Props = {
4444
};
4545

4646
export default function CreationForm({ step, steps, onCancel, onStepChange }: Props) {
47-
const notify = useNotification();
47+
const { success: notifySuccess, error: notifyError } = useAppNotification();
4848
const { data } = useSession();
4949

5050
const { push: navigate } = useRouter();
@@ -124,20 +124,16 @@ export default function CreationForm({ step, steps, onCancel, onStepChange }: Pr
124124
};
125125
const { data: resultCreation, error } = await tryCatch(createProject(id, formValues));
126126
if (error || !resultCreation || !resultCreation.data) {
127-
notify.error(
128-
'Project creation failed. Please check your details and try again.',
129-
undefined,
130-
'topRight',
131-
undefined
132-
);
127+
notifyError({
128+
message: 'Project creation failed. Please check your details and try again.',
129+
placement: 'topRight',
130+
});
133131
}
134132
if (resultCreation && resultCreation.data) {
135-
notify.success(
136-
`Your Project ${values.name} has been created successfully and is now ready to use.`,
137-
undefined,
138-
'topRight',
139-
undefined
140-
);
133+
notifySuccess({
134+
message: `Your Project ${values.name} has been created successfully and is now ready to use.`,
135+
placement: 'topRight',
136+
});
141137
refreshProjects();
142138
virtualLabDetailAtomFamily.remove(virtualLabId);
143139
navigate(`${generateVlProjectUrl(id, resultCreation.data.project.id)}/home`);

src/components/VirtualLab/create-entity-flows/virtual-lab/content.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import { motion } from 'framer-motion';
77
import { useSession } from 'next-auth/react';
88

99
import Overview from '@/components/VirtualLab/create-entity-flows/virtual-lab/overview';
10-
import useNotification from '@/hooks/notifications';
1110
import { CreateVirtualLabFooter } from '@/components/VirtualLab/create-entity-flows/virtual-lab/footer';
11+
import { useAppNotification } from '@/components/notification';
1212

1313
import { createVirtualLab } from '@/api/virtual-lab-svc/queries/virtual-lab';
1414
import { VirtualLabPayload } from '@/api/virtual-lab-svc/types';
1515
import { tryCatch } from '@/api/utils';
1616

1717
export default function CreateVirtualLabForm() {
1818
const { data } = useSession();
19-
const notify = useNotification();
19+
const notify = useAppNotification();
2020
const { push: navigate } = useRouter();
2121
const [form] = Form.useForm<VirtualLabPayload>();
2222
const [isFormValid, setIsFormValid] = useState(false);
@@ -47,20 +47,16 @@ export default function CreateVirtualLabForm() {
4747
startTransition(async () => {
4848
const { data: result, error } = await tryCatch(createVirtualLab(values));
4949
if (error || !result || !result.data) {
50-
notify.error(
51-
'Virtual Lab creation failed. Please check your details and try again.',
52-
undefined,
53-
'topRight',
54-
undefined
55-
);
50+
notify.error({
51+
message: 'Virtual Lab creation failed. Please check your details and try again.',
52+
placement: 'topRight',
53+
});
5654
}
5755
if (result && result.data) {
58-
notify.success(
59-
'Your Virtual Lab has been created successfully and is now ready to use.',
60-
undefined,
61-
'topRight',
62-
undefined
63-
);
56+
notify.success({
57+
message: 'Your Virtual Lab has been created successfully and is now ready to use.',
58+
placement: 'topRight',
59+
});
6460
resetForm();
6561
navigate(`/app/virtual-lab/lab/${result.data.virtual_lab.id}/overview`);
6662
}

src/components/neuron-viewer/index.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { secNamesAtom } from '@/state/simulate/single-neuron';
1212
import { DEFAULT_CURRENT_INJECTION_CONFIG } from '@/constants/simulate/single-neuron';
1313
import { recordingSourceForSimulationAtom } from '@/state/simulate/categories/recording-source-for-simulation';
1414
import { currentInjectionSimulationConfigAtom } from '@/state/simulate/categories/current-injection-simulation';
15-
import useNotification from '@/hooks/notifications';
15+
import { useAppNotification } from '@/components/notification';
1616

1717
type Props = {
1818
virtualLabId: string;
@@ -57,7 +57,7 @@ export default function NeuronViewer({
5757
const containerRef = useRef<HTMLDivElement>(null);
5858
const rendererRef = useRef<Renderer | null>(null);
5959
const setSecNames = useSetAtom(secNamesAtom);
60-
const { error: notifyError } = useNotification();
60+
const { error: notifyError } = useAppNotification();
6161

6262
const setSectionsAndSegments = useCallback(
6363
(morphology: Morphology) => {
@@ -98,13 +98,8 @@ export default function NeuronViewer({
9898
});
9999

100100
if (error) {
101-
notifyError(
102-
`Morphology initialization error: ${error}`,
103-
undefined,
104-
'topRight',
105-
undefined,
106-
error
107-
);
101+
notifyError({ message: `Morphology initialization error: ${error}`, placement: 'topRight' });
102+
return;
108103
}
109104

110105
useNeuronViewerEvents({
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { App } from 'antd';
2+
3+
export function useAppNotification() {
4+
const { notification } = App.useApp();
5+
return notification;
6+
}
7+
8+
export function useAppMessage() {
9+
const { message } = App.useApp();
10+
11+
return message;
12+
}
13+
14+
export function useAppModal() {
15+
const { modal } = App.useApp();
16+
17+
return modal;
18+
}

0 commit comments

Comments
 (0)