Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/fonts/Inter.otf
Binary file not shown.
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function App() {
if (!is_admin) {
try {
const voter = await contractInstance.getVoterdetails(account);

if (voter?.votername) {
is_voter = false;
}
Expand All @@ -47,6 +48,8 @@ function App() {
}
}

console.log('is_admin', is_admin);

dispatch({
type: 'LOGIN',
payload: { account, instance: contractInstance, is_admin, flag: is_voter },
Expand Down Expand Up @@ -74,6 +77,7 @@ function App() {
<Route path="active" element={<div>active election</div>} />
</Route>
<Route path="/admin" element={<AdminLayout />}>
<Route index element={<div>admin dashboard</div>} />
<Route path="verify-voters" element={<AdminVerifyVotersPage />} />
</Route>
<Route path="/candidate/add" element={<CandidatePage />} />
Expand Down
12 changes: 11 additions & 1 deletion src/components/shared/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useState } from 'react';
import { Link } from 'react-router';
import { Vote, Menu } from 'lucide-react';
import { Vote, Menu, Shield } from 'lucide-react';

import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button';
Expand All @@ -16,9 +16,11 @@ import {
} from '@/components/ui/navigation-menu';
import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet';
import { getCurrentConnection } from '@/config';
import AuthContext from '@/context/AuthContext';

export default function Navbar() {
const [isOpen, setIsOpen] = useState(false);
const { state } = React.useContext(AuthContext);
const is_connected = !!getCurrentConnection();

return (
Expand Down Expand Up @@ -82,6 +84,14 @@ export default function Navbar() {
</NavigationMenu>

<div className="flex items-center gap-4">
{state.is_admin ? (
<Button variant="ghost" size="sm" asChild className="hidden md:flex">
<Link to="/admin" className='font-medium'>
<Shield className="h-4 w-4" />
Admin
</Link>
</Button>
) : null}
<Button
className="hidden md:inline-flex hover:cursor-pointer disabled:opacity-80"
disabled={is_connected}
Expand Down
3 changes: 1 addition & 2 deletions src/components/shared/auth/Login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export function LoginForm() {
}

if (state.instance !== null) {
console.log('state.instance', state.instance);
await state.instance.methods.addVoter(state.account, values.name).send({
await state.instance.addVoter(state.account, values.name).send({
from: state.account,
gas: 1000000,
});
Expand Down
17 changes: 5 additions & 12 deletions src/components/shared/election/create-election.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import { toast } from 'sonner';
export function CreateElectionForm() {
const [error, setError] = React.useState<string | undefined>('');
const [isPending, startTransition] = React.useTransition();
const auth = React.useContext(AuthContext);

const { state } = auth;

const { state } = React.useContext(AuthContext);
const form = useForm<z.infer<typeof AddElectionSchema>>({
resolver: zodResolver(AddElectionSchema),
defaultValues: {
Expand All @@ -42,13 +39,10 @@ export function CreateElectionForm() {
}

if (state.instance !== null) {
const totalElections = await state.instance.methods.noOfElections().call();
console.log('instance', state.instance);
console.log('TotalElections', totalElections);
const totalElections = await state.instance.noOfElections();
console.log('totalElections', totalElections);
for (let i = 1; i <= totalElections; i++) {
const electionData = await state.instance.methods
.getElection(i)
.call({ from: state.account });
const electionData = await state.instance.getElection(i);
if (
electionData.purpose &&
electionData.purpose.toLowerCase() === values.purpose.toLowerCase()
Expand All @@ -58,8 +52,7 @@ export function CreateElectionForm() {
}
}

console.log('Creating election with purpose:', values.purpose);
await state.instance.methods.createElection(values.purpose).send({
await state.instance.createElection(values.purpose).send({
from: state.account,
gas: 1000000,
});
Expand Down
13 changes: 13 additions & 0 deletions src/components/ui/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { cn } from "@/lib/utils"

function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="skeleton"
className={cn("bg-primary/10 animate-pulse rounded-md", className)}
{...props}
/>
)
}

export { Skeleton }
13 changes: 12 additions & 1 deletion src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

@custom-variant dark (&:is(.dark *));

@font-face {
font-family: 'Inter';
src: url('/font/Inter.otf') format('opentype');
font-weight: normal;
font-style: normal;
}

body {
font-family: 'Inter', sans-serif;
}

:root {
/* Base */
--background: oklch(0.98 0.01 240); /* Very light blue-gray */
Expand Down Expand Up @@ -114,7 +125,7 @@
--sidebar-ring: oklch(0.6 0.2 250); /* Vibrant blue */
}

@theme inline {
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-card: var(--card);
Expand Down
10 changes: 3 additions & 7 deletions src/pages/CreateElection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import { CreateElectionForm } from '@/components/shared/election/create-election

const CreateElection = () => {
return (
<>
<div className="">
<div className="w-full max-w-xs">
<CreateElectionForm />
</div>
</div>
</>
<div className="w-full max-w-xs">
<CreateElectionForm />
</div>
);
};

Expand Down
Loading
Loading