mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-09 10:19:26 +00:00
66350b8fb5
Fixed an issue where users' chosen usernames were not being included when creating a room.
31 lines
743 B
TypeScript
31 lines
743 B
TypeScript
import { useMutation, UseMutationOptions } from '@tanstack/react-query'
|
|
import { fetchApi } from '@/api/fetchApi'
|
|
import { ApiError } from '@/api/ApiError'
|
|
import { ApiRoom } from './ApiRoom'
|
|
|
|
export interface CreateRoomParams {
|
|
slug: string
|
|
username?: string
|
|
}
|
|
|
|
const createRoom = ({
|
|
slug,
|
|
username = '',
|
|
}: CreateRoomParams): Promise<ApiRoom> => {
|
|
return fetchApi(`rooms/?username=${encodeURIComponent(username)}`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
name: slug,
|
|
}),
|
|
})
|
|
}
|
|
|
|
export function useCreateRoom(
|
|
options?: UseMutationOptions<ApiRoom, ApiError, CreateRoomParams>
|
|
) {
|
|
return useMutation<ApiRoom, ApiError, CreateRoomParams>({
|
|
mutationFn: createRoom,
|
|
onSuccess: options?.onSuccess,
|
|
})
|
|
}
|