@tscircuit/fake-snippets 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/bun-formatcheck.yml +26 -0
- package/.github/workflows/bun-test.yml +28 -0
- package/.github/workflows/bun-typecheck.yml +26 -0
- package/.github/workflows/bundle-size-analysis.yml +79 -0
- package/.github/workflows/playwright-test.yml +37 -0
- package/.github/workflows/stale.yml +40 -0
- package/.github/workflows/update-snapshots.yml +49 -0
- package/CONTRIBUTING.md +59 -0
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/biome.json +60 -0
- package/bun-tests/fake-snippets-api/fixtures/get-circuit-json.ts +148 -0
- package/bun-tests/fake-snippets-api/fixtures/get-test-server.ts +96 -0
- package/bun-tests/fake-snippets-api/fixtures/start-server.ts +44 -0
- package/bun-tests/fake-snippets-api/routes/accounts/get_account_balance.test.ts +18 -0
- package/bun-tests/fake-snippets-api/routes/health.test.ts +9 -0
- package/bun-tests/fake-snippets-api/routes/order_files/get.test.ts +48 -0
- package/bun-tests/fake-snippets-api/routes/order_files/upload.test.ts +77 -0
- package/bun-tests/fake-snippets-api/routes/orders/create.test.ts +19 -0
- package/bun-tests/fake-snippets-api/routes/orders/get.test.ts +38 -0
- package/bun-tests/fake-snippets-api/routes/orders/list.test.ts +30 -0
- package/bun-tests/fake-snippets-api/routes/orders/update.test.ts +46 -0
- package/bun-tests/fake-snippets-api/routes/snippets/add_star.test.ts +114 -0
- package/bun-tests/fake-snippets-api/routes/snippets/create.test.ts +28 -0
- package/bun-tests/fake-snippets-api/routes/snippets/delete.test.ts +106 -0
- package/bun-tests/fake-snippets-api/routes/snippets/download.test.ts +90 -0
- package/bun-tests/fake-snippets-api/routes/snippets/generate_from_jlcpcb.test.ts +25 -0
- package/bun-tests/fake-snippets-api/routes/snippets/get_image.test.ts +113 -0
- package/bun-tests/fake-snippets-api/routes/snippets/images.test.ts +112 -0
- package/bun-tests/fake-snippets-api/routes/snippets/list.test.ts +62 -0
- package/bun-tests/fake-snippets-api/routes/snippets/list_newest.test.ts +48 -0
- package/bun-tests/fake-snippets-api/routes/snippets/list_trending.test.ts +69 -0
- package/bun-tests/fake-snippets-api/routes/snippets/remove_star.test.ts +110 -0
- package/bun-tests/fake-snippets-api/routes/snippets/search.test.ts +75 -0
- package/bun-tests/fake-snippets-api/routes/snippets/star-count.test.ts +44 -0
- package/bun-tests/fake-snippets-api/routes/snippets/update.test.ts +116 -0
- package/bun-tests/parts-engine.test.ts +18 -0
- package/bun.lockb +0 -0
- package/bunfig.toml +2 -0
- package/components.json +20 -0
- package/dist/assets/editor_example_1-1000w.webp +0 -0
- package/dist/assets/editor_example_1-1200w.webp +0 -0
- package/dist/assets/editor_example_1-1600w.webp +0 -0
- package/dist/assets/editor_example_1-2000w.webp +0 -0
- package/dist/assets/editor_example_1-400w.webp +0 -0
- package/dist/assets/editor_example_1-600w.webp +0 -0
- package/dist/assets/editor_example_1-800w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1000w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1200w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1600w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-2000w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-400w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-600w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-800w.webp +0 -0
- package/dist/assets/editor_example_2-1000w.webp +0 -0
- package/dist/assets/editor_example_2-1200w.webp +0 -0
- package/dist/assets/editor_example_2-1600w.webp +0 -0
- package/dist/assets/editor_example_2-2000w.webp +0 -0
- package/dist/assets/editor_example_2-400w.webp +0 -0
- package/dist/assets/editor_example_2-600w.webp +0 -0
- package/dist/assets/editor_example_2-800w.webp +0 -0
- package/dist/assets/example_schematic-1000w.webp +0 -0
- package/dist/assets/example_schematic-1200w.webp +0 -0
- package/dist/assets/example_schematic-1600w.webp +0 -0
- package/dist/assets/example_schematic-2000w.webp +0 -0
- package/dist/assets/example_schematic-400w.webp +0 -0
- package/dist/assets/example_schematic-600w.webp +0 -0
- package/dist/assets/example_schematic-800w.webp +0 -0
- package/dist/bundle.js +3270 -0
- package/dist/robots.txt +9 -0
- package/dist/sitemap.xml +118 -0
- package/docs/CIRCUIT_JSON_SOURCE_COMPONENT_OVERVIEW.md +151 -0
- package/fake-snippets-api/README.md +6 -0
- package/fake-snippets-api/biome.json +47 -0
- package/fake-snippets-api/bun.lockb +0 -0
- package/fake-snippets-api/lib/db/autoload-dev-snippets.ts +84 -0
- package/fake-snippets-api/lib/db/autoload-snippets.json +24 -0
- package/fake-snippets-api/lib/db/db-client.ts +343 -0
- package/fake-snippets-api/lib/db/schema.ts +112 -0
- package/fake-snippets-api/lib/db/seed.ts +1608 -0
- package/fake-snippets-api/lib/middleware/with-ctx-error.ts +26 -0
- package/fake-snippets-api/lib/middleware/with-db.ts +15 -0
- package/fake-snippets-api/lib/middleware/with-error-handling.ts +24 -0
- package/fake-snippets-api/lib/middleware/with-optional-session-auth.ts +34 -0
- package/fake-snippets-api/lib/middleware/with-request-logging.ts +54 -0
- package/fake-snippets-api/lib/middleware/with-session-auth.ts +39 -0
- package/fake-snippets-api/lib/middleware/with-winter-spec.ts +24 -0
- package/fake-snippets-api/next-env.d.ts +5 -0
- package/fake-snippets-api/routes/api/accounts/get.ts +21 -0
- package/fake-snippets-api/routes/api/accounts/get_account_balance.ts +22 -0
- package/fake-snippets-api/routes/api/accounts/update.ts +32 -0
- package/fake-snippets-api/routes/api/ai/[...anyroute].ts +31 -0
- package/fake-snippets-api/routes/api/ai.ts +2 -0
- package/fake-snippets-api/routes/api/aistream/[...anyroute].ts +65 -0
- package/fake-snippets-api/routes/api/health.ts +9 -0
- package/fake-snippets-api/routes/api/internal/sessions/create_without_auth.ts +63 -0
- package/fake-snippets-api/routes/api/order_files/get.ts +28 -0
- package/fake-snippets-api/routes/api/order_files/upload.ts +43 -0
- package/fake-snippets-api/routes/api/orders/create.ts +41 -0
- package/fake-snippets-api/routes/api/orders/get.ts +28 -0
- package/fake-snippets-api/routes/api/orders/list.ts +15 -0
- package/fake-snippets-api/routes/api/orders/update.ts +50 -0
- package/fake-snippets-api/routes/api/snippets/add_star.ts +42 -0
- package/fake-snippets-api/routes/api/snippets/create.ts +55 -0
- package/fake-snippets-api/routes/api/snippets/delete.ts +41 -0
- package/fake-snippets-api/routes/api/snippets/download.ts +148 -0
- package/fake-snippets-api/routes/api/snippets/generate_from_jlcpcb.ts +55 -0
- package/fake-snippets-api/routes/api/snippets/get.ts +50 -0
- package/fake-snippets-api/routes/api/snippets/get_image.ts +65 -0
- package/fake-snippets-api/routes/api/snippets/images/[author]/[snippet_name]/[typeFormat].ts +74 -0
- package/fake-snippets-api/routes/api/snippets/list.ts +28 -0
- package/fake-snippets-api/routes/api/snippets/list_newest.ts +13 -0
- package/fake-snippets-api/routes/api/snippets/list_trending.ts +21 -0
- package/fake-snippets-api/routes/api/snippets/remove_star.ts +42 -0
- package/fake-snippets-api/routes/api/snippets/search.ts +18 -0
- package/fake-snippets-api/routes/api/snippets/update.ts +86 -0
- package/favicon.ico +0 -0
- package/index.html +23 -0
- package/landing.html +23 -0
- package/package.json +164 -0
- package/playwright-tests/ai-page.spec.ts +19 -0
- package/playwright-tests/cmd-click.spec.ts +43 -0
- package/playwright-tests/dashboard-page.spec.ts +10 -0
- package/playwright-tests/editor-page.spec.ts +15 -0
- package/playwright-tests/files-dialog.spec.ts +19 -0
- package/playwright-tests/footprint-dialog/footprint-dialog.spec.ts +27 -0
- package/playwright-tests/footprint-dialog/footprint-insertion.spec.ts +38 -0
- package/playwright-tests/footprint-dialog/footprint-preview.spec.ts +34 -0
- package/playwright-tests/footprint-dialog/footprint-selection.spec.ts +29 -0
- package/playwright-tests/handle-manual-edits.spec.ts +55 -0
- package/playwright-tests/home-page.spec.ts +10 -0
- package/playwright-tests/images.spec.ts +17 -0
- package/playwright-tests/manual-edits.spec.ts +89 -0
- package/playwright-tests/preview-page.spec.ts +14 -0
- package/playwright-tests/quickstart-page.spec.ts +10 -0
- package/playwright-tests/search-links.spec.ts +21 -0
- package/playwright-tests/search.spec.ts +27 -0
- package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-lg.png +0 -0
- package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-md.png +0 -0
- package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-xs.png +0 -0
- package/playwright-tests/snapshots/cmd-click.spec.ts-underlined-imports.png +0 -0
- package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-lg.png +0 -0
- package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-md.png +0 -0
- package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-xs.png +0 -0
- package/playwright-tests/snapshots/editor-page.spec.ts-editor-with-snippet.png +0 -0
- package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-lg.png +0 -0
- package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-md.png +0 -0
- package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-xs.png +0 -0
- package/playwright-tests/snapshots/files-dialog.spec.ts-view-snippet-files.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-lg.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-md.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-xs.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-lg.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-md.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-xs.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-lg.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-md.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-xs.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-lg.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-md.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-xs.png +0 -0
- package/playwright-tests/snapshots/handle-manual-edits.spec.ts-handle-manual-edits.png +0 -0
- package/playwright-tests/snapshots/home-page.spec.ts-Home-page-lg.png +0 -0
- package/playwright-tests/snapshots/home-page.spec.ts-Home-page-md.png +0 -0
- package/playwright-tests/snapshots/home-page.spec.ts-Home-page-xs.png +0 -0
- package/playwright-tests/snapshots/images.spec.ts-pcb-image.png +0 -0
- package/playwright-tests/snapshots/images.spec.ts-schematic-image.png +0 -0
- package/playwright-tests/snapshots/manual-edits.spec.ts-editor-manual-edits.png +0 -0
- package/playwright-tests/snapshots/manual-edits.spec.ts-manual-edits-view.png +0 -0
- package/playwright-tests/snapshots/preview-page.spec.ts-preview-snippet-pcb.png +0 -0
- package/playwright-tests/snapshots/preview-page.spec.ts-preview-snippet-schematic.png +0 -0
- package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagelg.png +0 -0
- package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagemd.png +0 -0
- package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagexs.png +0 -0
- package/playwright-tests/snapshots/search-links.spec.ts-search-links.png +0 -0
- package/playwright-tests/snapshots/search.spec.ts-search-lg.png +0 -0
- package/playwright-tests/snapshots/search.spec.ts-search-md.png +0 -0
- package/playwright-tests/snapshots/search.spec.ts-search-xs.png +0 -0
- package/playwright-tests/snapshots/star.spec.ts-remove-star-button.png +0 -0
- package/playwright-tests/snapshots/star.spec.ts-star-button.png +0 -0
- package/playwright-tests/snapshots/update-description.spec.ts-update-description.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-lg.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-md.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-xs.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-lg.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-md.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-xs.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-files.png +0 -0
- package/playwright-tests/star.spec.ts +40 -0
- package/playwright-tests/update-description.spec.ts +18 -0
- package/playwright-tests/view-snippet.spec.ts +35 -0
- package/playwright-tests/viewports.ts +5 -0
- package/playwright.config.ts +27 -0
- package/postcss.config.js +6 -0
- package/public/robots.txt +9 -0
- package/renovate.json +24 -0
- package/scripts/generate-image-sizes.ts +58 -0
- package/scripts/generate-sitemap.ts +103 -0
- package/scripts/generate_bundle_stats.js +192 -0
- package/scripts/snapshot.ts +35 -0
- package/src/App.tsx +113 -0
- package/src/ContextProviders.tsx +9 -0
- package/src/assets/originals/editor_example_1.webp +0 -0
- package/src/assets/originals/editor_example_1_more_square.webp +0 -0
- package/src/assets/originals/editor_example_2.webp +0 -0
- package/src/assets/originals/example_schematic.webp +0 -0
- package/src/components/AiChatInterface.tsx +221 -0
- package/src/components/AiChatMessage.tsx +86 -0
- package/src/components/Analytics.tsx +30 -0
- package/src/components/BomTable.tsx +69 -0
- package/src/components/ChatInput.tsx +53 -0
- package/src/components/CircuitToSvgWithMouseControl.tsx +78 -0
- package/src/components/CmdKMenu.tsx +301 -0
- package/src/components/CodeAndPreview.tsx +258 -0
- package/src/components/CodeEditor.tsx +460 -0
- package/src/components/CodeEditorHeader.tsx +160 -0
- package/src/components/CreateNewSnippetWithAiHero.tsx +77 -0
- package/src/components/DownloadButtonAndMenu.tsx +212 -0
- package/src/components/EditorNav.tsx +428 -0
- package/src/components/ErrorFallback.tsx +25 -0
- package/src/components/ErrorTabContent.tsx +122 -0
- package/src/components/FAQ.tsx +113 -0
- package/src/components/Footer.tsx +134 -0
- package/src/components/Footer2.tsx +100 -0
- package/src/components/FootprintDialog.tsx +342 -0
- package/src/components/Header.tsx +187 -0
- package/src/components/Header2.tsx +135 -0
- package/src/components/HeaderDropdown.tsx +83 -0
- package/src/components/HeaderLogin.tsx +94 -0
- package/src/components/JLCPCBImportDialog.tsx +155 -0
- package/src/components/LandingHero.tsx +175 -0
- package/src/components/LatestSnippets.tsx +39 -0
- package/src/components/OptimizedImage.tsx +96 -0
- package/src/components/OrderPreviewContent.tsx +61 -0
- package/src/components/ParametersEditor.tsx +140 -0
- package/src/components/PcbViewerWithContainerHeight.tsx +47 -0
- package/src/components/PrefetchPageLink.tsx +45 -0
- package/src/components/PreviewContent.tsx +375 -0
- package/src/components/PreviewEmptyState.tsx +16 -0
- package/src/components/RunButton.tsx +27 -0
- package/src/components/SearchComponent.tsx +163 -0
- package/src/components/ShippingInformationForm.tsx +423 -0
- package/src/components/SnippetLink.tsx +37 -0
- package/src/components/StaticPreviewContent.tsx +89 -0
- package/src/components/StaticViewSnippetHeader.tsx +70 -0
- package/src/components/StaticViewSnippetSidebar.tsx +100 -0
- package/src/components/TableViewer/CircuitJsonTableViewer.tsx +316 -0
- package/src/components/TableViewer/ClickableText.tsx +21 -0
- package/src/components/TableViewer/HeaderCell.tsx +27 -0
- package/src/components/TableViewer/Modal.tsx +39 -0
- package/src/components/TrendingSnippetCarousel.tsx +77 -0
- package/src/components/TypeBadge.tsx +31 -0
- package/src/components/ViewSnippetHeader.tsx +144 -0
- package/src/components/ViewSnippetSidebar.tsx +162 -0
- package/src/components/dialogs/confirm-delete-snippet-dialog.tsx +80 -0
- package/src/components/dialogs/create-order-dialog.tsx +146 -0
- package/src/components/dialogs/create-use-dialog.tsx +34 -0
- package/src/components/dialogs/edit-description-dialog.tsx +96 -0
- package/src/components/dialogs/files-dialog.tsx +70 -0
- package/src/components/dialogs/import-snippet-dialog.tsx +84 -0
- package/src/components/dialogs/rename-snippet-dialog.tsx +81 -0
- package/src/components/dialogs/view-ts-files-dialog.tsx +89 -0
- package/src/components/ui/accordion.tsx +55 -0
- package/src/components/ui/alert-dialog.tsx +139 -0
- package/src/components/ui/alert.tsx +59 -0
- package/src/components/ui/aspect-ratio.tsx +5 -0
- package/src/components/ui/avatar.tsx +48 -0
- package/src/components/ui/badge.tsx +36 -0
- package/src/components/ui/breadcrumb.tsx +118 -0
- package/src/components/ui/button.tsx +58 -0
- package/src/components/ui/calendar.tsx +73 -0
- package/src/components/ui/card.tsx +76 -0
- package/src/components/ui/carousel.tsx +260 -0
- package/src/components/ui/chart.tsx +363 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/collapsible.tsx +9 -0
- package/src/components/ui/combobox.tsx +178 -0
- package/src/components/ui/command.tsx +151 -0
- package/src/components/ui/context-menu.tsx +202 -0
- package/src/components/ui/dialog.tsx +120 -0
- package/src/components/ui/drawer.tsx +116 -0
- package/src/components/ui/dropdown-menu.tsx +203 -0
- package/src/components/ui/form.tsx +182 -0
- package/src/components/ui/hover-card.tsx +27 -0
- package/src/components/ui/input-otp.tsx +69 -0
- package/src/components/ui/input.tsx +25 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/menubar.tsx +238 -0
- package/src/components/ui/navigation-menu.tsx +129 -0
- package/src/components/ui/pagination.tsx +121 -0
- package/src/components/ui/popover.tsx +31 -0
- package/src/components/ui/progress.tsx +26 -0
- package/src/components/ui/radio-group.tsx +42 -0
- package/src/components/ui/resizable.tsx +43 -0
- package/src/components/ui/scroll-area.tsx +46 -0
- package/src/components/ui/searchable-select.tsx +94 -0
- package/src/components/ui/select.tsx +162 -0
- package/src/components/ui/separator.tsx +29 -0
- package/src/components/ui/sheet.tsx +141 -0
- package/src/components/ui/skeleton.tsx +18 -0
- package/src/components/ui/slider.tsx +26 -0
- package/src/components/ui/sonner.tsx +30 -0
- package/src/components/ui/switch.tsx +27 -0
- package/src/components/ui/table.tsx +120 -0
- package/src/components/ui/tabs.tsx +53 -0
- package/src/components/ui/textarea.tsx +24 -0
- package/src/components/ui/toast.tsx +128 -0
- package/src/components/ui/toaster.tsx +33 -0
- package/src/components/ui/toggle-group.tsx +59 -0
- package/src/components/ui/toggle.tsx +43 -0
- package/src/components/ui/tooltip.tsx +28 -0
- package/src/entry-server.tsx +12 -0
- package/src/hooks/use-account-balance.ts +24 -0
- package/src/hooks/use-ai-api.ts +35 -0
- package/src/hooks/use-axios.ts +20 -0
- package/src/hooks/use-code-completion-ai-api.ts +11 -0
- package/src/hooks/use-compiled-tsx.ts +37 -0
- package/src/hooks/use-copy-to-clipboard.ts +26 -0
- package/src/hooks/use-create-snippet-mutation.ts +62 -0
- package/src/hooks/use-current-snippet-id.ts +75 -0
- package/src/hooks/use-current-snippet.ts +24 -0
- package/src/hooks/use-global-store.ts +33 -0
- package/src/hooks/use-is-using-fake-api.ts +3 -0
- package/src/hooks/use-run-tsx/construct-circuit.tsx +64 -0
- package/src/hooks/use-run-tsx/eval-compiled-js.ts +9 -0
- package/src/hooks/use-run-tsx/index.tsx +251 -0
- package/src/hooks/use-save-snippet.ts +66 -0
- package/src/hooks/use-sign-in.ts +22 -0
- package/src/hooks/use-snippet-by-name.ts +25 -0
- package/src/hooks/use-snippet.ts +23 -0
- package/src/hooks/use-snippets-base-api-url.ts +3 -0
- package/src/hooks/use-toast.tsx +208 -0
- package/src/hooks/use-typecheck.ts +54 -0
- package/src/hooks/use-url-params.ts +31 -0
- package/src/hooks/use-warn-user-on-page-change.ts +23 -0
- package/src/hooks/useForkSnippetMutation.ts +52 -0
- package/src/index.css +21 -0
- package/src/lib/__tests__/constants.test.ts +66 -0
- package/src/lib/base64ToBytes.ts +5 -0
- package/src/lib/bytesToBase64.ts +4 -0
- package/src/lib/codemirror/basic-setup.ts +51 -0
- package/src/lib/constants.ts +12 -0
- package/src/lib/decodeUrlHashToText.ts +15 -0
- package/src/lib/defaultCodeForBlankCode.tsx +7 -0
- package/src/lib/download-fns/createBlobURL.ts +4 -0
- package/src/lib/download-fns/download-assembly-svg.ts +12 -0
- package/src/lib/download-fns/download-circuit-json-fn.ts +12 -0
- package/src/lib/download-fns/download-dsn-file-fn.ts +12 -0
- package/src/lib/download-fns/download-fabrication-files.ts +233 -0
- package/src/lib/download-fns/download-gltf.ts +49 -0
- package/src/lib/download-fns/download-kicad-files.ts +27 -0
- package/src/lib/download-fns/download-readable-netlist.ts +12 -0
- package/src/lib/download-fns/download-schematic-svg.ts +12 -0
- package/src/lib/download-fns/download-simple-route-json.ts +17 -0
- package/src/lib/encodeTextToUrlHash.ts +17 -0
- package/src/lib/get-snippet-template.ts +26 -0
- package/src/lib/handleManualEditsImport.tsx +65 -0
- package/src/lib/jlc-parts-engine.ts +69 -0
- package/src/lib/templates/blank-3d-model-template.ts +12 -0
- package/src/lib/templates/blank-circuit-board-template.ts +24 -0
- package/src/lib/templates/blank-footprint-template.ts +29 -0
- package/src/lib/templates/blank-package-template.ts +22 -0
- package/src/lib/templates/blinking-led-board-template.ts +63 -0
- package/src/lib/templates/manual-edits-template.ts +5 -0
- package/src/lib/templates/usb-c-led-flashlight-template.ts +22 -0
- package/src/lib/utils/checkIfManualEditsImported.ts +6 -0
- package/src/lib/utils/getSyntaxError.ts +13 -0
- package/src/lib/utils/index.ts +6 -0
- package/src/lib/utils/load-prettier.ts +18 -0
- package/src/lib/utils/parseFootprintParams.ts +52 -0
- package/src/lib/utils/parseJsonOrNull.ts +8 -0
- package/src/lib/utils/pcbManualEditEventHandler.ts +156 -0
- package/src/main.tsx +10 -0
- package/src/pages/ai.tsx +92 -0
- package/src/pages/authorize.tsx +54 -0
- package/src/pages/dashboard.tsx +165 -0
- package/src/pages/dev-login.tsx +68 -0
- package/src/pages/editor.tsx +28 -0
- package/src/pages/landing.tsx +236 -0
- package/src/pages/my-orders.tsx +54 -0
- package/src/pages/newest.tsx +16 -0
- package/src/pages/preview.tsx +70 -0
- package/src/pages/quickstart.tsx +198 -0
- package/src/pages/search.tsx +26 -0
- package/src/pages/settings.tsx +25 -0
- package/src/pages/user-profile.tsx +97 -0
- package/src/pages/view-order.tsx +123 -0
- package/src/pages/view-snippet.tsx +149 -0
- package/src/prettier.ts +9 -0
- package/src/vite-env.d.ts +1 -0
- package/tailwind.config.js +47 -0
- package/tsconfig.json +30 -0
- package/vercel.json +50 -0
- package/vite.config.ts +146 -0
- package/winterspec.config.ts +6 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Loader2Icon, PlayIcon } from "lucide-react"
|
|
2
|
+
import { Button } from "./ui/button"
|
|
3
|
+
|
|
4
|
+
export const RunButton = ({
|
|
5
|
+
onClick,
|
|
6
|
+
disabled,
|
|
7
|
+
isRunningCode,
|
|
8
|
+
}: {
|
|
9
|
+
onClick: () => void
|
|
10
|
+
disabled: boolean
|
|
11
|
+
isRunningCode?: boolean
|
|
12
|
+
}) => {
|
|
13
|
+
return (
|
|
14
|
+
<Button
|
|
15
|
+
className="bg-blue-600 hover:bg-blue-500 run-button"
|
|
16
|
+
onClick={onClick}
|
|
17
|
+
disabled={disabled || isRunningCode}
|
|
18
|
+
>
|
|
19
|
+
Run
|
|
20
|
+
{isRunningCode ? (
|
|
21
|
+
<Loader2Icon className="w-3 h-3 ml-2 animate-spin" />
|
|
22
|
+
) : (
|
|
23
|
+
<PlayIcon className="w-3 h-3 ml-2" />
|
|
24
|
+
)}
|
|
25
|
+
</Button>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Input } from "@/components/ui/input"
|
|
2
|
+
import { useAxios } from "@/hooks/use-axios"
|
|
3
|
+
import { useLocation } from "wouter"
|
|
4
|
+
import React, { useEffect, useRef, useState } from "react"
|
|
5
|
+
import { useQuery } from "react-query"
|
|
6
|
+
import { Alert } from "./ui/alert"
|
|
7
|
+
import { useSnippetsBaseApiUrl } from "@/hooks/use-snippets-base-api-url"
|
|
8
|
+
import { PrefetchPageLink } from "./PrefetchPageLink"
|
|
9
|
+
|
|
10
|
+
interface SearchComponentProps {
|
|
11
|
+
onResultsFetched?: (results: any[]) => void // optional
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const LinkWithNewTabHandling = ({
|
|
15
|
+
shouldOpenInNewTab,
|
|
16
|
+
href,
|
|
17
|
+
className,
|
|
18
|
+
children,
|
|
19
|
+
}: {
|
|
20
|
+
shouldOpenInNewTab: boolean
|
|
21
|
+
href: string
|
|
22
|
+
className?: string
|
|
23
|
+
children: React.ReactNode
|
|
24
|
+
}) => {
|
|
25
|
+
if (shouldOpenInNewTab) {
|
|
26
|
+
return (
|
|
27
|
+
<a
|
|
28
|
+
href={href}
|
|
29
|
+
target="_blank"
|
|
30
|
+
rel="noopener noreferrer"
|
|
31
|
+
className={className}
|
|
32
|
+
>
|
|
33
|
+
{children}
|
|
34
|
+
</a>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
return (
|
|
38
|
+
<PrefetchPageLink className={className} href={href}>
|
|
39
|
+
{children}
|
|
40
|
+
</PrefetchPageLink>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const SearchComponent: React.FC<SearchComponentProps> = ({
|
|
45
|
+
onResultsFetched,
|
|
46
|
+
}) => {
|
|
47
|
+
const [searchQuery, setSearchQuery] = useState("")
|
|
48
|
+
const [showResults, setShowResults] = useState(false)
|
|
49
|
+
const axios = useAxios()
|
|
50
|
+
const resultsRef = useRef<HTMLDivElement>(null)
|
|
51
|
+
const [location] = useLocation()
|
|
52
|
+
const { snippetsBaseApiUrl } = useSnippetsBaseApiUrl()
|
|
53
|
+
|
|
54
|
+
const { data: searchResults, isLoading } = useQuery(
|
|
55
|
+
["snippetSearch", searchQuery],
|
|
56
|
+
async () => {
|
|
57
|
+
if (!searchQuery) return []
|
|
58
|
+
const { data } = await axios.get("/snippets/search", {
|
|
59
|
+
params: { q: searchQuery },
|
|
60
|
+
})
|
|
61
|
+
if (onResultsFetched) {
|
|
62
|
+
onResultsFetched(data.snippets)
|
|
63
|
+
}
|
|
64
|
+
return data.snippets
|
|
65
|
+
},
|
|
66
|
+
{ enabled: Boolean(searchQuery) },
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
const handleSearch = (e: React.FormEvent) => {
|
|
70
|
+
e.preventDefault()
|
|
71
|
+
setShowResults(!!searchQuery)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
76
|
+
if (
|
|
77
|
+
resultsRef.current &&
|
|
78
|
+
!resultsRef.current.contains(event.target as Node)
|
|
79
|
+
) {
|
|
80
|
+
setShowResults(false)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
document.addEventListener("mousedown", handleClickOutside)
|
|
85
|
+
return () => {
|
|
86
|
+
document.removeEventListener("mousedown", handleClickOutside)
|
|
87
|
+
}
|
|
88
|
+
}, [])
|
|
89
|
+
|
|
90
|
+
const shouldOpenInNewTab = location === "/editor" || location === "/ai"
|
|
91
|
+
const shouldOpenInEditor = location === "/editor" || location === "/ai"
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<form onSubmit={handleSearch} className="relative">
|
|
95
|
+
<Input
|
|
96
|
+
type="search"
|
|
97
|
+
placeholder="Search"
|
|
98
|
+
className="pl-4 focus:border-blue-500 placeholder-gray-400 text-sm"
|
|
99
|
+
value={searchQuery}
|
|
100
|
+
onChange={(e) => {
|
|
101
|
+
setSearchQuery(e.target.value)
|
|
102
|
+
setShowResults(!!e.target.value)
|
|
103
|
+
}}
|
|
104
|
+
aria-label="Search snippets"
|
|
105
|
+
role="searchbox"
|
|
106
|
+
/>
|
|
107
|
+
{isLoading && (
|
|
108
|
+
<div className="absolute top-full left-0 right-0 mt-2 bg-white shadow-lg rounded-md z-10 p-2 flex items-center justify-center space-x-2">
|
|
109
|
+
<span className="text-gray-500 text-sm">Loading...</span>
|
|
110
|
+
</div>
|
|
111
|
+
)}
|
|
112
|
+
|
|
113
|
+
{showResults && searchResults && (
|
|
114
|
+
<div
|
|
115
|
+
ref={resultsRef}
|
|
116
|
+
className="absolute top-full md:left-0 right-0 mt-2 bg-white shadow-lg rounded-md z-10 w-80 max-h-screen overflow-y-auto overflow-x-visible"
|
|
117
|
+
>
|
|
118
|
+
{searchResults.length > 0 ? (
|
|
119
|
+
<ul className="divide-y divide-gray-200">
|
|
120
|
+
{searchResults.map((snippet: any) => (
|
|
121
|
+
<li key={snippet.snippet_id} className="p-2 hover:bg-gray-50">
|
|
122
|
+
<LinkWithNewTabHandling
|
|
123
|
+
href={
|
|
124
|
+
shouldOpenInEditor
|
|
125
|
+
? `/editor?snippet_id=${snippet.snippet_id}`
|
|
126
|
+
: `/${snippet.owner_name}/${snippet.unscoped_name}`
|
|
127
|
+
}
|
|
128
|
+
shouldOpenInNewTab={shouldOpenInNewTab}
|
|
129
|
+
className="flex"
|
|
130
|
+
>
|
|
131
|
+
<div className="w-12 h-12 overflow-hidden mr-2 flex-shrink-0 rounded-sm">
|
|
132
|
+
<img
|
|
133
|
+
src={`${useSnippetsBaseApiUrl()}/snippets/images/${snippet.owner_name}/${snippet.unscoped_name}/pcb.svg`}
|
|
134
|
+
alt={`PCB preview for ${snippet.name}`}
|
|
135
|
+
className="w-12 h-12 object-contain p-1 scale-[4] rotate-45"
|
|
136
|
+
/>
|
|
137
|
+
</div>
|
|
138
|
+
<div className="flex-grow">
|
|
139
|
+
<div className="font-medium text-blue-600 break-words text-xs">
|
|
140
|
+
{snippet.name}
|
|
141
|
+
</div>
|
|
142
|
+
{snippet.description && (
|
|
143
|
+
<div className="text-xs text-gray-500 break-words h-8 overflow-hidden">
|
|
144
|
+
{snippet.description}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
</div>
|
|
148
|
+
</LinkWithNewTabHandling>
|
|
149
|
+
</li>
|
|
150
|
+
))}
|
|
151
|
+
</ul>
|
|
152
|
+
) : (
|
|
153
|
+
<Alert variant="default" className="p-4">
|
|
154
|
+
No results found for "{searchQuery}"
|
|
155
|
+
</Alert>
|
|
156
|
+
)}
|
|
157
|
+
</div>
|
|
158
|
+
)}
|
|
159
|
+
</form>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export default SearchComponent
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import React, { useReducer, useEffect, useState } from "react"
|
|
2
|
+
import { Button } from "@/components/ui/button"
|
|
3
|
+
import { Input } from "@/components/ui/input"
|
|
4
|
+
import { useToast } from "@/hooks/use-toast"
|
|
5
|
+
import { useAxios } from "@/hooks/use-axios"
|
|
6
|
+
import { useQuery, useMutation, useQueryClient } from "react-query"
|
|
7
|
+
import { Loader2 } from "lucide-react"
|
|
8
|
+
import { getNames } from "country-list"
|
|
9
|
+
import states from "states-us"
|
|
10
|
+
import { Alert, AlertDescription } from "@/components/ui/alert"
|
|
11
|
+
import { SearchableSelect } from "@/components/ui/searchable-select"
|
|
12
|
+
|
|
13
|
+
const USA = "United States of America"
|
|
14
|
+
|
|
15
|
+
type ShippingInfo = {
|
|
16
|
+
firstName: string
|
|
17
|
+
lastName: string
|
|
18
|
+
companyName: string
|
|
19
|
+
address: string
|
|
20
|
+
apartment: string
|
|
21
|
+
city: string
|
|
22
|
+
state: string
|
|
23
|
+
zipCode: string
|
|
24
|
+
country: string
|
|
25
|
+
phone: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Action =
|
|
29
|
+
| { type: "SET_FIELD"; field: keyof ShippingInfo; value: string }
|
|
30
|
+
| { type: "SET_ALL"; payload: ShippingInfo }
|
|
31
|
+
|
|
32
|
+
const initialState: ShippingInfo = {
|
|
33
|
+
firstName: "",
|
|
34
|
+
lastName: "",
|
|
35
|
+
companyName: "",
|
|
36
|
+
address: "",
|
|
37
|
+
apartment: "",
|
|
38
|
+
zipCode: "",
|
|
39
|
+
country: USA,
|
|
40
|
+
city: "",
|
|
41
|
+
state: "",
|
|
42
|
+
phone: "",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const shippingPlaceholders: ShippingInfo = {
|
|
46
|
+
firstName: "Enter your first name",
|
|
47
|
+
lastName: "Enter your last name",
|
|
48
|
+
companyName: "Enter company name (optional)",
|
|
49
|
+
address: "Enter your street address",
|
|
50
|
+
apartment: "Apartment, suite, unit etc. (optional)",
|
|
51
|
+
zipCode: "Enter your zip code",
|
|
52
|
+
country: "Select your country",
|
|
53
|
+
city: "Enter your city",
|
|
54
|
+
state: "Enter your state",
|
|
55
|
+
phone: "Enter your phone number",
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const ShippingInformationForm: React.FC = () => {
|
|
59
|
+
const [form, setField] = useReducer(
|
|
60
|
+
(state: ShippingInfo, action: Action): ShippingInfo => {
|
|
61
|
+
switch (action.type) {
|
|
62
|
+
case "SET_FIELD":
|
|
63
|
+
return { ...state, [action.field]: action.value }
|
|
64
|
+
case "SET_ALL":
|
|
65
|
+
return action.payload
|
|
66
|
+
default:
|
|
67
|
+
return state
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
initialState,
|
|
71
|
+
)
|
|
72
|
+
const { toast } = useToast()
|
|
73
|
+
const axios = useAxios()
|
|
74
|
+
const queryClient = useQueryClient()
|
|
75
|
+
const [countries] = useState(getNames())
|
|
76
|
+
const [isPhoneValid, setIsPhoneValid] = useState(true)
|
|
77
|
+
|
|
78
|
+
const { data: account, isLoading: isLoadingAccount } = useQuery(
|
|
79
|
+
"account",
|
|
80
|
+
async () => {
|
|
81
|
+
const response = await axios.get("/accounts/get")
|
|
82
|
+
return response.data.account
|
|
83
|
+
},
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
const updateShippingMutation = useMutation(
|
|
87
|
+
(shippingInfo: ShippingInfo) =>
|
|
88
|
+
axios.post("/accounts/update", { shippingInfo }),
|
|
89
|
+
{
|
|
90
|
+
onSuccess: () => {
|
|
91
|
+
queryClient.invalidateQueries("account")
|
|
92
|
+
toast({
|
|
93
|
+
title: "Success",
|
|
94
|
+
description: "Shipping information updated successfully",
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
onError: () => {
|
|
98
|
+
toast({
|
|
99
|
+
title: "Error",
|
|
100
|
+
description: "Failed to update shipping information",
|
|
101
|
+
variant: "destructive",
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (account?.shippingInfo) {
|
|
109
|
+
setField({
|
|
110
|
+
type: "SET_ALL",
|
|
111
|
+
payload: {
|
|
112
|
+
...account.shippingInfo,
|
|
113
|
+
country: account.shippingInfo.country || USA,
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
}, [account])
|
|
118
|
+
|
|
119
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
120
|
+
e.preventDefault()
|
|
121
|
+
updateShippingMutation.mutate(form)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (isLoadingAccount) {
|
|
125
|
+
return (
|
|
126
|
+
<div className="flex justify-center items-center h-64">
|
|
127
|
+
<Loader2 className="w-8 h-8 animate-spin" />
|
|
128
|
+
</div>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div className="space-y-4">
|
|
134
|
+
<div>
|
|
135
|
+
<label
|
|
136
|
+
htmlFor="country"
|
|
137
|
+
className="block text-sm font-medium text-gray-700"
|
|
138
|
+
>
|
|
139
|
+
Country <span className="text-red-500">*</span>
|
|
140
|
+
</label>
|
|
141
|
+
<SearchableSelect
|
|
142
|
+
options={countries.map((country) => ({
|
|
143
|
+
value: country,
|
|
144
|
+
label: country,
|
|
145
|
+
}))}
|
|
146
|
+
value={form.country}
|
|
147
|
+
onChange={(value) =>
|
|
148
|
+
setField({ type: "SET_FIELD", field: "country", value })
|
|
149
|
+
}
|
|
150
|
+
resourceType="country"
|
|
151
|
+
/>
|
|
152
|
+
{form.country !== USA && (
|
|
153
|
+
<Alert variant="destructive" className="mt-2">
|
|
154
|
+
<AlertDescription>
|
|
155
|
+
Currently, only shipping to the US is supported.{" "}
|
|
156
|
+
<a
|
|
157
|
+
href={`https://github.com/tscircuit/snippets/issues/new?title=${encodeURIComponent("Shipping to " + form.country)}&body=${encodeURIComponent("Please add support for shipping to " + form.country + ".")}`}
|
|
158
|
+
target="_blank"
|
|
159
|
+
rel="noopener noreferrer"
|
|
160
|
+
className="font-medium underline"
|
|
161
|
+
>
|
|
162
|
+
Create an Issue
|
|
163
|
+
</a>
|
|
164
|
+
</AlertDescription>
|
|
165
|
+
</Alert>
|
|
166
|
+
)}
|
|
167
|
+
</div>
|
|
168
|
+
<div>
|
|
169
|
+
<label
|
|
170
|
+
htmlFor="companyName"
|
|
171
|
+
className="block text-sm font-medium text-gray-700"
|
|
172
|
+
>
|
|
173
|
+
Company Name
|
|
174
|
+
</label>
|
|
175
|
+
<Input
|
|
176
|
+
id="companyName"
|
|
177
|
+
value={form.companyName}
|
|
178
|
+
onChange={(e) =>
|
|
179
|
+
setField({
|
|
180
|
+
type: "SET_FIELD",
|
|
181
|
+
field: "companyName",
|
|
182
|
+
value: e.target.value,
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
placeholder={shippingPlaceholders.companyName}
|
|
186
|
+
disabled={updateShippingMutation.isLoading}
|
|
187
|
+
/>
|
|
188
|
+
</div>
|
|
189
|
+
<div className="flex gap-4">
|
|
190
|
+
<div className="flex-1">
|
|
191
|
+
<label
|
|
192
|
+
htmlFor="firstName"
|
|
193
|
+
className="block text-sm font-medium text-gray-700"
|
|
194
|
+
>
|
|
195
|
+
First Name <span className="text-red-500">*</span>
|
|
196
|
+
</label>
|
|
197
|
+
<Input
|
|
198
|
+
id="firstName"
|
|
199
|
+
value={form.firstName}
|
|
200
|
+
onChange={(e) =>
|
|
201
|
+
setField({
|
|
202
|
+
type: "SET_FIELD",
|
|
203
|
+
field: "firstName",
|
|
204
|
+
value: e.target.value,
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
placeholder={shippingPlaceholders.firstName}
|
|
208
|
+
disabled={updateShippingMutation.isLoading}
|
|
209
|
+
required
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
<div className="flex-1">
|
|
213
|
+
<label
|
|
214
|
+
htmlFor="lastName"
|
|
215
|
+
className="block text-sm font-medium text-gray-700"
|
|
216
|
+
>
|
|
217
|
+
Last Name <span className="text-red-500">*</span>
|
|
218
|
+
</label>
|
|
219
|
+
<Input
|
|
220
|
+
id="lastName"
|
|
221
|
+
value={form.lastName}
|
|
222
|
+
onChange={(e) =>
|
|
223
|
+
setField({
|
|
224
|
+
type: "SET_FIELD",
|
|
225
|
+
field: "lastName",
|
|
226
|
+
value: e.target.value,
|
|
227
|
+
})
|
|
228
|
+
}
|
|
229
|
+
placeholder={shippingPlaceholders.lastName}
|
|
230
|
+
disabled={updateShippingMutation.isLoading}
|
|
231
|
+
required
|
|
232
|
+
/>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
<div>
|
|
236
|
+
<label
|
|
237
|
+
htmlFor="address"
|
|
238
|
+
className="block text-sm font-medium text-gray-700"
|
|
239
|
+
>
|
|
240
|
+
Address <span className="text-red-500">*</span>
|
|
241
|
+
</label>
|
|
242
|
+
<Input
|
|
243
|
+
id="address"
|
|
244
|
+
value={form.address}
|
|
245
|
+
onChange={(e) =>
|
|
246
|
+
setField({
|
|
247
|
+
type: "SET_FIELD",
|
|
248
|
+
field: "address",
|
|
249
|
+
value: e.target.value,
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
placeholder={shippingPlaceholders.address}
|
|
253
|
+
disabled={updateShippingMutation.isLoading}
|
|
254
|
+
required
|
|
255
|
+
/>
|
|
256
|
+
</div>
|
|
257
|
+
<div>
|
|
258
|
+
<label
|
|
259
|
+
htmlFor="apartment"
|
|
260
|
+
className="block text-sm font-medium text-gray-700"
|
|
261
|
+
>
|
|
262
|
+
Apartment, suite, unit etc.
|
|
263
|
+
</label>
|
|
264
|
+
<Input
|
|
265
|
+
id="apartment"
|
|
266
|
+
value={form.apartment}
|
|
267
|
+
onChange={(e) =>
|
|
268
|
+
setField({
|
|
269
|
+
type: "SET_FIELD",
|
|
270
|
+
field: "apartment",
|
|
271
|
+
value: e.target.value,
|
|
272
|
+
})
|
|
273
|
+
}
|
|
274
|
+
placeholder={shippingPlaceholders.apartment}
|
|
275
|
+
disabled={updateShippingMutation.isLoading}
|
|
276
|
+
/>
|
|
277
|
+
</div>
|
|
278
|
+
<div className="flex gap-4">
|
|
279
|
+
<div className="flex-1">
|
|
280
|
+
<label
|
|
281
|
+
htmlFor="city"
|
|
282
|
+
className="block text-sm font-medium text-gray-700"
|
|
283
|
+
>
|
|
284
|
+
Town / City <span className="text-red-500">*</span>
|
|
285
|
+
</label>
|
|
286
|
+
<Input
|
|
287
|
+
id="city"
|
|
288
|
+
value={form.city}
|
|
289
|
+
onChange={(e) =>
|
|
290
|
+
setField({
|
|
291
|
+
type: "SET_FIELD",
|
|
292
|
+
field: "city",
|
|
293
|
+
value: e.target.value,
|
|
294
|
+
})
|
|
295
|
+
}
|
|
296
|
+
placeholder={shippingPlaceholders.city}
|
|
297
|
+
disabled={updateShippingMutation.isLoading}
|
|
298
|
+
required
|
|
299
|
+
/>
|
|
300
|
+
</div>
|
|
301
|
+
<div className="flex-1">
|
|
302
|
+
<label
|
|
303
|
+
htmlFor="state"
|
|
304
|
+
className="block text-sm font-medium text-gray-700"
|
|
305
|
+
>
|
|
306
|
+
State{" "}
|
|
307
|
+
{form.country === USA && <span className="text-red-500">*</span>}
|
|
308
|
+
</label>
|
|
309
|
+
{form.country === USA ? (
|
|
310
|
+
<SearchableSelect
|
|
311
|
+
options={states.map((state) => ({
|
|
312
|
+
value: state.name,
|
|
313
|
+
label: state.name,
|
|
314
|
+
}))}
|
|
315
|
+
value={form.state}
|
|
316
|
+
onChange={(value) =>
|
|
317
|
+
setField({ type: "SET_FIELD", field: "state", value })
|
|
318
|
+
}
|
|
319
|
+
resourceType="state"
|
|
320
|
+
/>
|
|
321
|
+
) : (
|
|
322
|
+
<Input
|
|
323
|
+
id="state"
|
|
324
|
+
value={form.state}
|
|
325
|
+
onChange={(e) =>
|
|
326
|
+
setField({
|
|
327
|
+
type: "SET_FIELD",
|
|
328
|
+
field: "state",
|
|
329
|
+
value: e.target.value,
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
placeholder={shippingPlaceholders.state}
|
|
333
|
+
disabled={updateShippingMutation.isLoading}
|
|
334
|
+
/>
|
|
335
|
+
)}
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
<div>
|
|
339
|
+
<label
|
|
340
|
+
htmlFor="zipCode"
|
|
341
|
+
className="block text-sm font-medium text-gray-700"
|
|
342
|
+
>
|
|
343
|
+
Postcode / Zip <span className="text-red-500">*</span>
|
|
344
|
+
</label>
|
|
345
|
+
<Input
|
|
346
|
+
id="zipCode"
|
|
347
|
+
value={form.zipCode}
|
|
348
|
+
onChange={(e) =>
|
|
349
|
+
setField({
|
|
350
|
+
type: "SET_FIELD",
|
|
351
|
+
field: "zipCode",
|
|
352
|
+
value: e.target.value,
|
|
353
|
+
})
|
|
354
|
+
}
|
|
355
|
+
placeholder={shippingPlaceholders.zipCode}
|
|
356
|
+
disabled={updateShippingMutation.isLoading}
|
|
357
|
+
required
|
|
358
|
+
/>
|
|
359
|
+
</div>
|
|
360
|
+
<div>
|
|
361
|
+
<label
|
|
362
|
+
htmlFor="phone"
|
|
363
|
+
className="block text-sm font-medium text-gray-700"
|
|
364
|
+
>
|
|
365
|
+
Phone <span className="text-red-500">*</span>
|
|
366
|
+
</label>
|
|
367
|
+
<div>
|
|
368
|
+
<Input
|
|
369
|
+
id="phone"
|
|
370
|
+
type="tel"
|
|
371
|
+
value={form.phone}
|
|
372
|
+
onChange={(e) => {
|
|
373
|
+
setIsPhoneValid(true)
|
|
374
|
+
setField({
|
|
375
|
+
type: "SET_FIELD",
|
|
376
|
+
field: "phone",
|
|
377
|
+
value: e.target.value,
|
|
378
|
+
})
|
|
379
|
+
}}
|
|
380
|
+
onBlur={() => {
|
|
381
|
+
const phoneRegex =
|
|
382
|
+
/^(\+\d{1,2}\s?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/
|
|
383
|
+
setIsPhoneValid(phoneRegex.test(form.phone))
|
|
384
|
+
}}
|
|
385
|
+
placeholder={shippingPlaceholders.phone}
|
|
386
|
+
disabled={updateShippingMutation.isLoading}
|
|
387
|
+
required
|
|
388
|
+
/>
|
|
389
|
+
<p className="text-xs text-gray-500 mt-1">
|
|
390
|
+
Format: (123) 456-7890 or +1 123-456-7890
|
|
391
|
+
</p>
|
|
392
|
+
{!isPhoneValid && form.phone && (
|
|
393
|
+
<Alert variant="destructive" className="mt-2">
|
|
394
|
+
<AlertDescription>
|
|
395
|
+
Please enter a valid phone number.
|
|
396
|
+
</AlertDescription>
|
|
397
|
+
</Alert>
|
|
398
|
+
)}
|
|
399
|
+
</div>
|
|
400
|
+
</div>
|
|
401
|
+
<Button
|
|
402
|
+
type="submit"
|
|
403
|
+
disabled={
|
|
404
|
+
updateShippingMutation.isLoading ||
|
|
405
|
+
form.country !== USA ||
|
|
406
|
+
!isPhoneValid
|
|
407
|
+
}
|
|
408
|
+
onClick={handleSubmit}
|
|
409
|
+
>
|
|
410
|
+
{updateShippingMutation.isLoading ? (
|
|
411
|
+
<>
|
|
412
|
+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
413
|
+
Updating...
|
|
414
|
+
</>
|
|
415
|
+
) : (
|
|
416
|
+
"Update"
|
|
417
|
+
)}
|
|
418
|
+
</Button>
|
|
419
|
+
</div>
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export default ShippingInformationForm
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Link } from "wouter"
|
|
2
|
+
import { Star } from "lucide-react"
|
|
3
|
+
|
|
4
|
+
export const SnippetLink = ({
|
|
5
|
+
snippet,
|
|
6
|
+
}: {
|
|
7
|
+
snippet: {
|
|
8
|
+
owner_name: string
|
|
9
|
+
name: string
|
|
10
|
+
unscoped_name: string
|
|
11
|
+
star_count?: number
|
|
12
|
+
}
|
|
13
|
+
}) => {
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
<Link
|
|
17
|
+
className="text-blue-500 font-semibold hover:underline"
|
|
18
|
+
href={`/${snippet.owner_name}`}
|
|
19
|
+
>
|
|
20
|
+
{snippet.owner_name}
|
|
21
|
+
</Link>
|
|
22
|
+
<span className="px-0.5 text-gray-500">/</span>
|
|
23
|
+
<Link
|
|
24
|
+
className="text-blue-500 font-semibold hover:underline"
|
|
25
|
+
href={`/${snippet.name}`}
|
|
26
|
+
>
|
|
27
|
+
{snippet.unscoped_name}
|
|
28
|
+
</Link>
|
|
29
|
+
{snippet.star_count !== undefined && (
|
|
30
|
+
<span className="ml-2 text-gray-500 text-xs flex items-center">
|
|
31
|
+
<Star className="w-3 h-3 mr-1" />
|
|
32
|
+
{snippet.star_count}
|
|
33
|
+
</span>
|
|
34
|
+
)}
|
|
35
|
+
</>
|
|
36
|
+
)
|
|
37
|
+
}
|