|
| 1 | +import { toast } from 'sonner' |
| 2 | + |
| 3 | +import { |
| 4 | + Dialog, |
| 5 | + DialogContent, |
| 6 | + DialogFooter, |
| 7 | + DialogHeader, |
| 8 | + DialogTitle, |
| 9 | +} from '@/components/ui/dialog' |
| 10 | +import { StartersCarousel } from '@/components/starters-carousel' |
| 11 | +import { Button } from '@/components/ui/button' |
| 12 | +import { Switch } from '@/components/ui/switch' |
| 13 | +import { Label } from '@/components/ui/label' |
| 14 | +import { |
| 15 | + setProjectStarter, |
| 16 | + useApplicationMode, |
| 17 | + useRegistry, |
| 18 | + useStartupDialog, |
| 19 | +} from '@/store/project' |
| 20 | +import { loadRemoteStarter } from '@/lib/api' |
| 21 | + |
| 22 | +export default function StartupDialog() { |
| 23 | + const mode = useApplicationMode() |
| 24 | + const registry = useRegistry() |
| 25 | + const { open, setOpen, dontShowAgain, setDontShowAgain } = useStartupDialog() |
| 26 | + |
| 27 | + if (mode !== 'setup' || !registry) { |
| 28 | + return null |
| 29 | + } |
| 30 | + |
| 31 | + async function onImport(registryUrl: string) { |
| 32 | + const data = await loadRemoteStarter(registryUrl) |
| 33 | + |
| 34 | + if ('error' in data) { |
| 35 | + toast.error('Failed to load starter', { |
| 36 | + description: data.error, |
| 37 | + }) |
| 38 | + } else { |
| 39 | + setProjectStarter(data) |
| 40 | + setOpen(false) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return ( |
| 45 | + <Dialog modal open={open} onOpenChange={setOpen}> |
| 46 | + <DialogContent className="sm:min-w-[425px] sm:max-w-fit"> |
| 47 | + <DialogHeader> |
| 48 | + <DialogTitle className="text-center text-2xl font-bold"> |
| 49 | + Would you like to use a starter project? |
| 50 | + </DialogTitle> |
| 51 | + </DialogHeader> |
| 52 | + {registry?.starters && ( |
| 53 | + <div> |
| 54 | + <StartersCarousel onImport={onImport} /> |
| 55 | + </div> |
| 56 | + )} |
| 57 | + <DialogFooter className="flex sm:justify-between w-full"> |
| 58 | + <div className="flex items-center gap-2"> |
| 59 | + <Switch |
| 60 | + id="show-startup-dialog" |
| 61 | + checked={dontShowAgain} |
| 62 | + onCheckedChange={setDontShowAgain} |
| 63 | + /> |
| 64 | + <Label htmlFor="show-startup-dialog">Don't show this again</Label> |
| 65 | + </div> |
| 66 | + <Button onClick={() => setOpen(false)}> |
| 67 | + No, I want to start from scratch |
| 68 | + </Button> |
| 69 | + </DialogFooter> |
| 70 | + </DialogContent> |
| 71 | + </Dialog> |
| 72 | + ) |
| 73 | +} |
0 commit comments