|
|
@@ -26,18 +26,22 @@ export default function ShareModal({ isOpen, onClose, image }: ShareModalProps)
|
|
|
const maxLinks = isAuthenticated ? 10 : 3;
|
|
|
const expiryOptions = isAuthenticated ? SHARE_LINK_EXPIRY_OPTIONS : ANON_EXPIRY_OPTIONS;
|
|
|
|
|
|
+ // Use shortCode if available, otherwise use image.id as identifier
|
|
|
+ // This allows logged-in users (who don't have shortCodes) to create share links
|
|
|
+ const imageIdentifier = image.shortCode || image.id;
|
|
|
+
|
|
|
const loadLinks = useCallback(async () => {
|
|
|
- if (!image.shortCode) return;
|
|
|
+ if (!imageIdentifier) return;
|
|
|
setIsLoading(true);
|
|
|
try {
|
|
|
- const data = await listShareLinks(client, image.shortCode);
|
|
|
+ const data = await listShareLinks(client, imageIdentifier);
|
|
|
setLinks(data);
|
|
|
} catch (err) {
|
|
|
setError(err instanceof Error ? err.message : 'Failed to load links');
|
|
|
} finally {
|
|
|
setIsLoading(false);
|
|
|
}
|
|
|
- }, [image.shortCode, client]);
|
|
|
+ }, [imageIdentifier, client]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (isOpen) {
|
|
|
@@ -46,12 +50,12 @@ export default function ShareModal({ isOpen, onClose, image }: ShareModalProps)
|
|
|
}, [isOpen, loadLinks]);
|
|
|
|
|
|
const handleCreateLink = async () => {
|
|
|
- if (!image.shortCode) return;
|
|
|
+ if (!imageIdentifier) return;
|
|
|
setIsCreating(true);
|
|
|
setError(null);
|
|
|
try {
|
|
|
const sessionToken = getSessionToken();
|
|
|
- await createShareLink(client, image.shortCode, expiresIn, sessionToken, image.id);
|
|
|
+ await createShareLink(client, imageIdentifier, expiresIn, sessionToken, image.id);
|
|
|
await loadLinks();
|
|
|
} catch (err) {
|
|
|
setError(err instanceof Error ? err.message : 'Failed to create link');
|
|
|
@@ -61,7 +65,6 @@ export default function ShareModal({ isOpen, onClose, image }: ShareModalProps)
|
|
|
};
|
|
|
|
|
|
const handleRevokeLink = async (linkCode: string) => {
|
|
|
- if (!image.shortCode) return;
|
|
|
try {
|
|
|
await revokeShareLink(client, linkCode);
|
|
|
await loadLinks();
|