Skip to content

Commit

Permalink
feat: add support for user register
Browse files Browse the repository at this point in the history
  • Loading branch information
feelware committed Nov 22, 2024
1 parent 8419ff4 commit 28aa35b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 26 deletions.
10 changes: 10 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@react-three/fiber": "^8.17.10",
"@tabler/icons-react": "^3.11.0",
"konva": "^9.3.16",
"lucide-react": "^0.460.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-konva": "^18.2.10",
Expand Down
16 changes: 9 additions & 7 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const App = () => {
<div style={{ height: '100vh' }}>
<Switch>
{
routes.map((route, i) => (
<Route
key={i}
path={route.href}
component={route.component as any}
/>
))
routes.map((route, i) => {
return (
<Route
key={i}
path={route.href}
component={route.component as any}
/>
)
})
}
</Switch>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/UserButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const UserButton = () => {
{
icon: IconLogout,
label: 'Cerrar sesión',
onClick: () => { },
onClick: () => localStorage.removeItem('metagallery-token'),
},
];

Expand Down
6 changes: 2 additions & 4 deletions app/src/pages/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Menu, Search, Share2 } from "lucide-react";
import styles from "./GalleryDashboard.module.css";
import { UserButton } from "@/components/UserButton";

const galleries = [
{
Expand Down Expand Up @@ -43,10 +44,7 @@ export const GalleryDashboard = () => {
<Menu className={styles.menuIcon} />
<span className={styles.srOnly}>Dashboard</span>
</button>
<div className={styles.headerRight}>
<span className={styles.userName}>Van Gogh</span>
<button className={styles.upgradeButton}>Mejora tu plan</button>
</div>
<UserButton />
</div>
</header>

Expand Down
1 change: 0 additions & 1 deletion app/src/pages/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Gallery3D } from '../Gallery3D';
export const Editor = ({ gallery }: { gallery: string }) => {
const [projectName, setProjectName] = useState('Nueva galería');
const [previewOpened, setPreviewOpened] = useState(false);

return (
<>
<section style={{ minWidth: '420px', position: 'relative', overflow: 'hidden' }}>
Expand Down
45 changes: 38 additions & 7 deletions app/src/pages/Home/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Button from './Button';
import styles from './Header.module.css';
import Popup from './PopUp/Popup';
import popupStyles from './PopUp/Popup.module.css';
import { useLocation } from 'wouter';

export const Header = () => {
const [loginPopup, setLoginPopup] = useState(false);
Expand All @@ -20,13 +21,15 @@ export const Header = () => {

const [isLoading, setIsLoading] = useState(false);
const [loginError, setLoginError] = useState('');
const [, setLocation] = useLocation();

const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
setIsLoading(true);
setLoginError('');

try {
const response = await fetch('/services/stiller/auth/login', {
const response = await fetch('https://pandadiestro.xyz/services/stiller/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -41,8 +44,8 @@ export const Header = () => {

const token = await response.text();
console.log('Login successful. Token:', token);

localStorage.setItem('authToken', token);
localStorage.setItem('metagallery-token', token);
setLocation('/dashboard');
} catch (error: any) {
console.error('Login error details:', error);
}
Expand All @@ -69,6 +72,37 @@ export const Header = () => {
setCvv('');
};

const handleRegister = async (e: React.FormEvent) => {
e.preventDefault();
try {
const response = await fetch('https://pandadiestro.xyz/services/stiller/auth/newuser', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
tier_id: 0,
username,
mail: email,
pwd: password,
}),
});

if (!response.ok) {
const errorDetails = await response.text();
console.error('Failed to register:', errorDetails);
return;
}

const token = await response.text();
console.log('Registration successful. Token:', token);
localStorage.setItem('metagallery-token', token);
setLocation('/dashboard');
} catch (e) {
console.error('Failed to register:', e);
}
}

return (
<header className={styles.header}>
<h1 className={styles.title}>Metagallery</h1>
Expand Down Expand Up @@ -198,10 +232,7 @@ export const Header = () => {
<>
<h3 className={popupStyles.title}>Registro de usuario</h3>
<p className={popupStyles.description}>Completa tus datos adicionales</p>
<form onSubmit={(e) => {
e.preventDefault();
setRegisterStep(3);
}}>
<form onSubmit={handleRegister}>
<div className={popupStyles.formgroup}>
<label className={popupStyles.label} htmlFor="address">
Dirección
Expand Down
14 changes: 8 additions & 6 deletions app/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Header } from "./components/Header";
import PricingSection from "./components/PricingCardSection";

export const Home = () => (
<>
<Header />
<PricingSection />
</>
);
export const Home = () => {
return (
<>
<Header />
<PricingSection />
</>
);
};

0 comments on commit 28aa35b

Please sign in to comment.