Skip to content

Commit

Permalink
feat: implementation news routes to app and user dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
renancorreadev committed Nov 5, 2024
1 parent 7f94fc8 commit a7d125e
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,26 @@ export class ClientBlockchainAdapter implements ClientBlockchainTokenOutputPort
tokenID: clientID,
customer: name,
description: 'Voce ainda não alcançou nenhuma insignia e nenhum nivel',
image: 'https://meusite.com/imagens/nft/1.png',
image:
'https://github.com/renancorreadev/loyahub/blob/develop/docs/images/Insignias/CustomerPremium.png?raw=true',
insight: 'sem insignia',
attributes: {
level: 0,
points: 0,
benefits: [
{
level_type: 'Nível',
value: 0,
},
{
nft_type: 'NFT',
value: 'Sem NFT',
},
{
benefit_type: 'Benefits',
value: [],
},
],
},
attributes: [
{
type: 'level_type',
value: 0,
},
{
type: 'nft_type',
value: 'Sem NFT',
},
{
type: 'benefit_type',
value: [],
},
],
id: clientID,
createdAt: new Date().toISOString(), // Data de criação atual
updatedAt: new Date().toISOString(), // Data de atualização atual
});

const config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class MetadataAdapter implements MetadataTokenOutputPort {

constructor(
@Inject(DependencyInjectionTokens.METADATA_STORAGE_OUTPUT_PORT)
private metadataStorage: MetadataStorageOutputPort,
private readonly metadataStorage: MetadataStorageOutputPort,
) {}

/**
Expand Down
30 changes: 12 additions & 18 deletions packages/loyahub-app/src/components/app/Auth/AuthDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,41 @@ import {
DialogFooter,
} from '@/components/ui';
import { Login } from '../Login';
import { RegisterForm } from '../UserRegister';

import { useNavigate } from 'react-router-dom';

export const AuthDialog: React.FC = () => {
const [isRegistering, setIsRegistering] = useState(false);
const [isOpen, setIsOpen] = useState(false);
const navigate = useNavigate();

const handleRegisterClick = () => {
setIsRegistering(true);
navigate('/register');
setIsOpen(false); // Fecha o Dialog
navigate('/register'); // Navega para a página de registro
};

return (
<Dialog>
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>
<Button variant="outline">
{isRegistering ? 'Back to Login' : 'Login/Register'}
<Button variant="outline" onClick={() => setIsOpen(true)}>
Login/Register
</Button>
</DialogTrigger>
<DialogContent className="flex flex-col items-center sm:max-w-md w-full mx-auto p-4">
<DialogHeader className="w-full">
<DialogTitle>
{isRegistering ? 'Register' : 'Login to Your Account'}
</DialogTitle>
<DialogTitle>Login to Your Account</DialogTitle>
<DialogDescription>
{isRegistering
? 'Please enter your details to register.'
: 'Please enter your email and password below to continue.'}
Please enter your email and password below to continue.
</DialogDescription>
</DialogHeader>
{isRegistering ? <RegisterForm /> : <Login />}
<Login />
<DialogFooter className="w-full mt-4 flex justify-end space-x-4">
<Button
variant="outline"
size="lg"
className="w-auto"
onClick={() => {
isRegistering ? setIsRegistering(false) : handleRegisterClick();
}}
onClick={handleRegisterClick}
>
{isRegistering ? 'Back to Login' : 'Register'}
Register
</Button>
</DialogFooter>
</DialogContent>
Expand Down
3 changes: 3 additions & 0 deletions packages/loyahub-app/src/pages/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ export const Dashboard = () => {
{new Date(metadata?.updatedAt || '').toLocaleDateString()}
</p>
</div>
</div>

<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-1 lg:px-24 gap-4 mb-8 justify-center ">
<div className="bg-gradient-to-r from-blue-500 to-blue-700 text-white rounded-lg shadow p-4 text-center">
<h3 className="text-lg font-semibold">Pontos</h3>
<p className="text-2xl font-bold">
Expand Down
65 changes: 47 additions & 18 deletions packages/loyahub-app/src/shared/Header/HeaderProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
MenuItem,
Transition,
} from '@headlessui/react';
import { CogIcon } from '@heroicons/react/24/outline'; // Importando ícone de dashboard
import { CogIcon } from '@heroicons/react/24/outline';
import React from 'react';
import { Link } from 'react-router-dom';

export const HeaderProfile = () => {
const { email, userData, isLogged } = useUserStore();
const { email, userData, isLogged, logout } = useUserStore();

if (!isLogged || !userData) return <p>Loading...</p>;

Expand All @@ -33,7 +33,7 @@ export const HeaderProfile = () => {
<div className="flex items-center gap-4">
<div>
<p className="text-lg tracking-tight text-slate-300 mb-1">
Olá, {email ? formatUserName(email) : 'Usuário'}
Hello, {email ? formatUserName(email) : 'User'}
</p>
</div>
{/** @ts-ignore */}
Expand Down Expand Up @@ -64,26 +64,55 @@ export const HeaderProfile = () => {
to="/dashboard"
className={`${
active ? 'bg-gray-100' : ''
} flex items-center gap-2 px-4 py-2 text-sm text-gray-700 transition-colors duration-150`}
} flex items-center gap-2 px-4 py-2 text-sm text-gray-700 transition-colors duration-150 `}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className="size-6"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 0 1 3 19.875v-6.75ZM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125V8.625ZM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125V4.125Z"
/>
</svg>
<div className="w-5">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 0 1 3 19.875v-6.75ZM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125V8.625ZM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125V4.125Z"
/>
</svg>
</div>
Dashboard
</Link>
)}
</MenuItem>

<MenuItem>
{({ active }: { active: boolean }) => (
<button
onClick={() => logout()}
className={`${
active ? 'bg-gray-100' : ''
} flex items-center gap-2 w-full px-4 py-2 text-sm text-gray-700 transition-colors duration-150`}
>
<div className="w-5">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 9V5.25a2.25 2.25 0 00-2.25-2.25H6.75A2.25 2.25 0 004.5 5.25v13.5A2.25 2.25 0 006.75 21h6.75a2.25 2.25 0 002.25-2.25V15M18 12h-9m0 0l3-3m-3 3l3 3"
/>
</svg>
</div>
Logout
</button>
)}
</MenuItem>
</MenuItems>
</Transition>
</Menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,27 @@ func (updater *MetadataUpdaterURI) UpdateMetadata(ctx context.Context, clientID

func determineMetadata(clientID string, newPoints int64, thresholds domain.Thresholds) (domain.Metadata, error) {
clientIDBigInt := new(big.Int)
clientIDBigInt.SetString(clientID, 10) // Converte clientID de string para *big.Int
clientIDBigInt.SetString(clientID, 10)

clientName, err := initialize.InitializeCustomerSC(clientIDBigInt)
if err != nil {
return domain.Metadata{}, fmt.Errorf("erro ao obter nome do cliente: %s", err)
}


imageURL := "https://github.com/renancorreadev/loyahub/blob/develop/docs/images/Insignias/CustomerPremium.png?raw=true"
if newPoints >= thresholds.PointsForPremium && newPoints < thresholds.PointsForGold {
imageURL = "https://github.com/renancorreadev/loyahub/blob/develop/docs/images/Insignias/CustomerPremium.png?raw=true"
} else if newPoints >= thresholds.PointsForGold && newPoints < thresholds.PointsForTitanium {
imageURL = "https://github.com/renancorreadev/loyahub/blob/develop/docs/images/Insignias/CustomerGOld.png?raw=true"
} else if newPoints >= thresholds.PointsForTitanium {
imageURL = "https://github.com/renancorreadev/loyahub/blob/develop/docs/images/Insignias/CustomerTitanium.png?raw=true"
}

metadata := domain.Metadata{
TokenID: clientID,
Customer: clientName,
Image: "https://meusite.com/imagens/nft/1.png",
Image: imageURL,
}

switch {
Expand Down

0 comments on commit a7d125e

Please sign in to comment.