mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
feat: migrate components to React Query hooks
- Add comprehensive API hooks for all operations - Migrate rooms page to use React Query mutations - Update transcript title component to use mutation hook - Refactor share/privacy component with proper error handling - Remove direct API client usage in favor of hooks
This commit is contained in:
@@ -19,7 +19,7 @@ import {
|
||||
createListCollection,
|
||||
} from "@chakra-ui/react";
|
||||
import { LuShare2 } from "react-icons/lu";
|
||||
import useApi from "../../lib/useApi";
|
||||
import { useTranscriptUpdate } from "../../lib/api-hooks";
|
||||
import useSessionUser from "../../lib/useSessionUser";
|
||||
import { CustomSession } from "../../lib/types";
|
||||
import ShareLink from "./shareLink";
|
||||
@@ -54,12 +54,9 @@ export default function ShareAndPrivacy(props: ShareAndPrivacyProps) {
|
||||
);
|
||||
const [shareLoading, setShareLoading] = useState(false);
|
||||
const requireLogin = featureEnabled("requireLogin");
|
||||
const api = useApi();
|
||||
const updateTranscriptMutation = useTranscriptUpdate();
|
||||
|
||||
const updateShareMode = async (selectedValue: string) => {
|
||||
if (!api)
|
||||
throw new Error("ShareLink's API should always be ready at this point");
|
||||
|
||||
const selectedOption = shareOptionsData.find(
|
||||
(option) => option.value === selectedValue,
|
||||
);
|
||||
@@ -71,16 +68,23 @@ export default function ShareAndPrivacy(props: ShareAndPrivacyProps) {
|
||||
share_mode: selectedValue as "public" | "semi-private" | "private",
|
||||
};
|
||||
|
||||
const updatedTranscript = await api.v1TranscriptUpdate({
|
||||
transcriptId: props.transcriptResponse.id,
|
||||
requestBody,
|
||||
});
|
||||
setShareMode(
|
||||
shareOptionsData.find(
|
||||
(option) => option.value === updatedTranscript.share_mode,
|
||||
) || shareOptionsData[0],
|
||||
);
|
||||
setShareLoading(false);
|
||||
try {
|
||||
const updatedTranscript = await updateTranscriptMutation.mutateAsync({
|
||||
params: {
|
||||
path: { transcript_id: props.transcriptResponse.id },
|
||||
},
|
||||
body: requestBody,
|
||||
});
|
||||
setShareMode(
|
||||
shareOptionsData.find(
|
||||
(option) => option.value === (updatedTranscript as any).share_mode,
|
||||
) || shareOptionsData[0],
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Failed to update share mode:", err);
|
||||
} finally {
|
||||
setShareLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const userId = useSessionUser().id;
|
||||
|
||||
Reference in New Issue
Block a user