import { ArrowRight } from '@phosphor-icons/react'; import { useQueryClient } from '@tanstack/react-query'; import { useNavigate } from 'react-router'; import { HardwareModel, useBridgeMutation, useZodForm } from '@sd/client'; import { Dialog, toast, useDialog, UseDialogProps, z } from '@sd/ui'; import { Icon } from '~/components'; import { useLocale } from '~/hooks'; import { hardwareModelToIcon } from '~/util/hardware'; import { usePlatform } from '~/util/Platform'; export default ( props: { device_name: string; device_model: HardwareModel; library_name: string; } & UseDialogProps ) => { // PROPS = device_name, device_model, library_name // you will probably have to change the props to accept the library id and device id to pair them properly. Omitted for now as // unsure what the data will look like when the backend is populated // const joinLibrary = useBridgeMutation(['cloud.library.join']); const { t } = useLocale(); const navigate = useNavigate(); const platform = usePlatform(); const queryClient = useQueryClient(); const form = useZodForm({ defaultValues: { libraryId: 'select_library' } }); // adapted from another dialog - we can change the form submit/remove form if needed but didn't want to // unnecessarily remove code const onSubmit = form.handleSubmit(async (data) => { try { // const library = await joinLibrary.mutateAsync(data.libraryId); const library = { uuid: '1234' }; // dummy data queryClient.setQueryData(['library.list'], (libraries: any) => { // The invalidation system beat us to it if ((libraries || []).find((l: any) => l.uuid === library.uuid)) return libraries; return [...(libraries || []), library]; }); if (platform.refreshMenuBar) platform.refreshMenuBar(); navigate(`/${library.uuid}`, { replace: true }); } catch (e: any) { console.error(e); toast.error(e); } }); return ( {/* device */}

{props.device_name}

{/* library */}

{props.library_name}

); };