mirror of
https://github.com/spliit-app/spliit.git
synced 2026-02-25 17:06:13 +01:00
* I18n with next-intl * package-lock * Finnish translations * Development fix * Use locale for positioning currency symbol * Translations: Expenses.ActiveUserModal * Translations: group 404 * Better translation for ExpenseCard * Apply translations in CategorySelect search * Fix for Finnish translation * Translations for ExpenseDocumentsInput * Translations for CreateFromReceipt * Fix for Finnish translation * Translations for schema errors * Fix for Finnish translation * Fixes for Finnish translations * Prettier --------- Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
import { getGroupInfoAction } from '@/app/groups/add-group-by-url-button-actions'
|
|
import { saveRecentGroup } from '@/app/groups/recent-groups-helpers'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Input } from '@/components/ui/input'
|
|
import {
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from '@/components/ui/popover'
|
|
import { useMediaQuery } from '@/lib/hooks'
|
|
import { Loader2, Plus } from 'lucide-react'
|
|
import { useTranslations } from 'next-intl'
|
|
import { useState } from 'react'
|
|
|
|
type Props = {
|
|
reload: () => void
|
|
}
|
|
|
|
export function AddGroupByUrlButton({ reload }: Props) {
|
|
const t = useTranslations('Groups.AddByURL')
|
|
const isDesktop = useMediaQuery('(min-width: 640px)')
|
|
const [url, setUrl] = useState('')
|
|
const [error, setError] = useState(false)
|
|
const [open, setOpen] = useState(false)
|
|
const [pending, setPending] = useState(false)
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<PopoverTrigger asChild>
|
|
<Button variant="secondary">
|
|
{/* <Plus className="w-4 h-4 mr-2" /> */}
|
|
{t('button')}
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent
|
|
align={isDesktop ? 'end' : 'start'}
|
|
className="[&_p]:text-sm flex flex-col gap-3"
|
|
>
|
|
<h3 className="font-bold">{t('title')}</h3>
|
|
<p>{t('description')}</p>
|
|
<form
|
|
className="flex gap-2"
|
|
onSubmit={async (event) => {
|
|
event.preventDefault()
|
|
const [, groupId] =
|
|
url.match(
|
|
new RegExp(`${window.location.origin}/groups/([^/]+)`),
|
|
) ?? []
|
|
setPending(true)
|
|
const group = groupId ? await getGroupInfoAction(groupId) : null
|
|
setPending(false)
|
|
if (!group) {
|
|
setError(true)
|
|
} else {
|
|
saveRecentGroup({ id: group.id, name: group.name })
|
|
reload()
|
|
setUrl('')
|
|
setOpen(false)
|
|
}
|
|
}}
|
|
>
|
|
<Input
|
|
type="url"
|
|
required
|
|
placeholder="https://spliit.app/..."
|
|
className="flex-1 text-base"
|
|
value={url}
|
|
disabled={pending}
|
|
onChange={(event) => {
|
|
setUrl(event.target.value)
|
|
setError(false)
|
|
}}
|
|
/>
|
|
<Button size="icon" type="submit" disabled={pending}>
|
|
{pending ? (
|
|
<Loader2 className="w-4 h-4 animate-spin" />
|
|
) : (
|
|
<Plus className="w-4 h-4" />
|
|
)}
|
|
</Button>
|
|
</form>
|
|
{error && <p className="text-destructive">{t('error')}</p>}
|
|
</PopoverContent>
|
|
</Popover>
|
|
)
|
|
}
|