import { ArrowRight } from '@phosphor-icons/react'; import { useQueryClient } from '@tanstack/react-query'; import { useNavigate } from 'react-router'; import { CloudDevice, CloudP2PNotifyUser, CloudP2PTicket, CloudSyncGroupWithDevices, 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'; type ReceivedJoinRequest = Extract; export default ( props: { data: ReceivedJoinRequest['data']; } & 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' } }); const userResponse = useBridgeMutation('cloud.userResponse'); // 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 (_d) => { try { // const library = await joinLibrary.mutateAsync(data.libraryId); userResponse.mutate({ kind: 'AcceptDeviceInSyncGroup', data: { ticket: props.data.ticket, accepted: { id: props.data.sync_group.library.pub_id, name: props.data.sync_group.library.name, description: null } } }); queryClient.setQueryData(['library.list'], (libraries: any) => { // The invalidation system beat us to it if ( (libraries || []).find( (l: any) => l.uuid === props.data.sync_group.library.pub_id ) ) return libraries; return [...(libraries || []), props.data.sync_group.library]; }); if (platform.refreshMenuBar) platform.refreshMenuBar(); navigate(`/${props.data.sync_group.library.pub_id}`, { replace: true }); } catch (e: any) { console.error(e); toast.error(e); } }); return ( {/* device */}

{props.data.asking_device.name}

{/* library */}

{props.data.sync_group.library.name}

); };