Skip to content

Commit

Permalink
Add auth page
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-fontaine committed Jun 4, 2023
1 parent ddd6f96 commit 21e9322
Show file tree
Hide file tree
Showing 18 changed files with 1,541 additions and 41 deletions.
19 changes: 18 additions & 1 deletion packages/octent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,35 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@hookform/resolvers": "^3.1.0",
"@nangohq/frontend": "^0.17.3",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@tanstack/router": "0.0.1-beta.89",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
"lucide-react": "^0.233.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-hook-form": "^7.44.3",
"tailwind-merge": "^1.13.0",
"tailwindcss-animate": "^1.0.5",
"zod": "^3.21.4",
"zustand": "^4.3.8"
},
"devDependencies": {
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@vitejs/plugin-react": "^4.0.0",
"autoprefixer": "^10.4.14",
"eslint": "^8.38.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4",
"postcss": "^8.4.24",
"tailwindcss": "^3.3.2",
"typescript": "^5.0.2",
"vite": "^4.3.9"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/octent/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
100 changes: 94 additions & 6 deletions packages/octent/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,101 @@
import React from 'react'
import {
Outlet,
RootRoute,
Route,
Router,
RouterProvider,
} from '@tanstack/router'
import React, { useCallback, useContext } from 'react'

import './globals.css'

import { OctentOptionsContext, OctentOptionsProvider } from './contexts/octent-options-context'
import { useAuth } from './hooks/use-auth'
import { HttpsGitAuthenticationPage } from './pages/authentication/https-git-authentication-page'

import type { OctentOptions } from '.'

// import { GithubAuthenticationPage } from './pages/authentication/github-authentication-page'

function navigate(url: Exclude<Parameters<typeof router.getRoute>[0], '__root__'>) {
location.href = url
}

function Root() {
const renavigate = useCallback((type: string) => {
if (type !== 'none')
// navigate('/dashboard')
console.log('Navigate to dashboard')
else
navigate('/')
}, [])

useAuth.subscribe((state) => {
renavigate(state.type)
})

const authenticationType = useAuth(state => state.type)
renavigate(authenticationType)

return <Outlet />
}

const rootRoute = new RootRoute({
component: Root,
})

function Index() {
const options = useContext(OctentOptionsContext)

const parsedRepositoryUrl = new URL(options.repositoryUrl)

switch (parsedRepositoryUrl.hostname) {
// case 'github.com': {
// console.error('GitHub authentication is not supported yet')
// }
default: {
if (parsedRepositoryUrl.protocol === 'https:')
navigate('/authentication/other')

if (parsedRepositoryUrl.protocol === 'ssh:')
console.error('SSH authentication is not supported yet')
}
}

return <></>
}

const indexRoute = new Route({
path: '/',
component: Index,
getParentRoute: () => rootRoute,
})

const httpsGitAuthenticationRoute = new Route({
path: '/authentication/other',
component: HttpsGitAuthenticationPage,
getParentRoute: () => rootRoute,
})

const routeTree = rootRoute.addChildren([
indexRoute,
httpsGitAuthenticationRoute,
])

const router = new Router({ routeTree })

declare module '@tanstack/router' {
interface Register {
router: typeof router
}
}

function App(props: OctentOptions) {
return (
<div className="App">
{JSON.stringify(props)}
</div>
)
return <div className="App bg-background text-foreground h-screen w-screen">
<OctentOptionsProvider value={props}>
<RouterProvider router={router} />
</OctentOptionsProvider>
</div>
}

export default App
55 changes: 55 additions & 0 deletions packages/octent/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Slot } from '@radix-ui/react-slot'
import { type VariantProps, cva } from 'class-variance-authority'
import * as React from 'react'

import { cn } from '@/lib/utils'

const buttonVariants = cva(
'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background',
{
variants: {
variant: {
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
destructive:
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
outline:
'border border-input hover:bg-accent hover:text-accent-foreground',
secondary:
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'underline-offset-4 hover:underline text-primary',
},
size: {
default: 'h-10 py-2 px-4',
sm: 'h-9 px-3 rounded-md',
lg: 'h-11 px-8 rounded-md',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
},
},
)

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : 'button'
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
)
},
)
Button.displayName = 'Button'

export { Button, buttonVariants }
79 changes: 79 additions & 0 deletions packages/octent/src/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as React from "react"

import { cn } from "@/lib/utils"

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-lg border bg-card text-card-foreground shadow-sm",
className
)}
{...props}
/>
))
Card.displayName = "Card"

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
))
CardHeader.displayName = "CardHeader"

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
CardTitle.displayName = "CardTitle"

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
CardDescription.displayName = "CardDescription"

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
))
CardContent.displayName = "CardContent"

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(" flex items-center p-6 pt-0", className)}
{...props}
/>
))
CardFooter.displayName = "CardFooter"

export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
Loading

0 comments on commit 21e9322

Please sign in to comment.