Skip to content

Commit b207e96

Browse files
authored
feat(generate): display login modal on unauthenticated upload (#1752)
1 parent 43a588f commit b207e96

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

packages/slice-machine/src/features/customTypes/customTypesBuilder/CreateSliceFromImageModal/CreateSliceFromImageModal.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ export function CreateSliceFromImageModal(
140140
});
141141
};
142142

143+
const failAndPromptLogin = () => {
144+
toast.error("Please log in and try again.");
145+
closeModal();
146+
openLoginModal();
147+
};
148+
143149
const uploadImage = async (args: {
144150
index: number;
145151
image: File;
@@ -170,8 +176,9 @@ export function CreateSliceFromImageModal(
170176
thumbnailUrl: imageUrl,
171177
}),
172178
});
173-
} catch {
179+
} catch (error) {
174180
if (currentId !== id.current) return;
181+
175182
setSlice({
176183
index,
177184
slice: (prevSlice) => ({
@@ -180,6 +187,11 @@ export function CreateSliceFromImageModal(
180187
onRetry: () => void uploadImage({ index, image, source }),
181188
}),
182189
});
190+
191+
if (isUnauthenticatedError(error)) {
192+
failAndPromptLogin();
193+
return;
194+
}
183195
}
184196
};
185197

@@ -301,9 +313,7 @@ export function CreateSliceFromImageModal(
301313
});
302314

303315
if (isUnauthenticatedError(error)) {
304-
toast.error("Please log in and try again.");
305-
closeModal();
306-
openLoginModal();
316+
failAndPromptLogin();
307317
return;
308318
}
309319

0 commit comments

Comments
 (0)