Skip to content

Commit

Permalink
add proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Oct 6, 2024
1 parent cab1a8f commit bcf68e0
Show file tree
Hide file tree
Showing 20 changed files with 969 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/ui/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import {
User,
User2Icon,
UserX2Icon,
X
X,
HandHelping,
Cog
} from 'lucide-react';

export type Icon = LucideIcon;
Expand All @@ -38,6 +40,7 @@ export const Icons = {
logo: Command,
login: LogIn,
close: X,
cog: Cog,
profile: User2Icon,
spinner: Loader2,
kanban: CircuitBoardIcon,
Expand All @@ -60,6 +63,7 @@ export const Icons = {
sun: SunMedium,
moon: Moon,
laptop: Laptop,
handHelping: HandHelping,
gitHub: ({ ...props }: LucideProps) => (
<svg
aria-hidden="true"
Expand Down
12 changes: 12 additions & 0 deletions src/constants/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ export const navItems: NavItem[] = [
icon: 'user',
label: 'Member'
},
{
title: 'Proposals',
href: '/proposal',
icon: 'handHelping',
label: 'Proposal'
},
{
title: 'Settings',
href: '/settings',
icon: 'cog',
label: 'Settings'
},
{
title: 'Login',
href: '/login',
Expand Down
22 changes: 22 additions & 0 deletions src/lib/dao/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Wallet } from '../near';

export const DAO_ID = 'build.sputnik-dao.near';

export async function getConfig(wallet: Wallet): Promise<any> {
try {
const config = await wallet.viewMethod({
contractId: DAO_ID,
method: 'get_config'
});

const { metadata } = config;
if (metadata) {
config.metadata = JSON.parse(atob(metadata));
}

return config;
} catch (error) {
console.log(error);
throw error;
}
}
3 changes: 2 additions & 1 deletion src/lib/dao/members.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Wallet } from '@/lib/near';
import { DAO_ID } from './config';

export type Member = {
id: string;
Expand Down Expand Up @@ -36,7 +37,7 @@ const processPolicy = (policy) => {
export async function getMembers(wallet: Wallet): Promise<Member[]> {
try {
const policy = await wallet.viewMethod({
contractId: 'build.sputnik-dao.near',
contractId: DAO_ID,
method: 'get_policy'
});
const daoDetails = processPolicy(policy);
Expand Down
57 changes: 57 additions & 0 deletions src/lib/dao/proposals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Wallet } from '../near';
import { DAO_ID } from './config';

export type Proposal = {
id: number;
proposer: string;
description: string;
kind: AddMemberToRole | FunctionCall;
status: 'Approved' | 'Rejected' | 'Pending' | 'InProgress' | 'Failed';
vote_counts: {
council: [number, number, number] | Record<string, never>;
};
votes: {
[key: string]: 'Approve' | 'Reject' | 'Abstain' | string;
};
submission_time: string;
};

type AddMemberToRole = {
AddMemberToRole: {
member_id: string;
role: string;
};
};

type FunctionCall = {
FunctionCall: {
receiver_id: string;
actions: {
method_name: string;
args: string; // Base64 encoded arguments
deposit: string;
gas: string;
}[];
};
};

export async function getProposals(
offset: number,
limit: number,
wallet: Wallet
): Promise<Proposal[]> {
try {
const proposals = await wallet.viewMethod({
contractId: DAO_ID,
method: 'get_proposals',
args: {
from_index: offset,
limit
}
});
return proposals;
} catch (error) {
console.log(error);
throw error;
}
}
142 changes: 142 additions & 0 deletions src/pages/proposals/ProposalDetailPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import Heading from '@/components/shared/heading';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader } from '@/components/ui/card';
import { useRouter } from '@/routes/hooks';
import { ChevronLeftIcon, ShareIcon } from 'lucide-react';
import { useSearchParams } from 'react-router-dom';
import ProposalFeedTable from './components/proposal-feed-table';
import { useGetProposals } from './queries/queries';

export default function ProposalDetailPage() {
const [searchParams] = useSearchParams();
const page = Number(searchParams.get('page') || 1);
const pageLimit = Number(searchParams.get('limit') || 10);
const country = searchParams.get('search') || null;
const offset = (page - 1) * pageLimit;
const { data, isLoading } = useGetProposals();
const users = data?.users;
const totalUsers = data?.total_users; //1000
const pageCount = Math.ceil(totalUsers / pageLimit);
const router = useRouter();
if (isLoading) {
return <h1>Loading!!!</h1>;
}
return (
<div className="p-10">
<div className="flex items-center justify-between">
<Heading title={'Personal Details'} />
<div className="flex justify-end gap-3">
<Button>
<ShareIcon className="h-4 w-4" />
Share
</Button>
<Button onClick={() => router.back()}>
<ChevronLeftIcon className="h-4 w-4" />
Back
</Button>
</div>
</div>
<div className="grid grid-cols-1 gap-6 py-6 lg:grid-cols-4">
<div className=" col-span-1 flex flex-col gap-6 lg:col-span-1">
<Card className="bg-secondary shadow-[rgba(50,50,93,0.25)_0px_6px_12px_-2px,_rgba(0,0,0,0.3)_0px_3px_7px_-3px] drop-shadow-sm">
<CardHeader className="flex flex-row items-center justify-between font-bold">
<p className="text-xl"> Profile</p>
<Badge className="bg-green-600">Active</Badge>
</CardHeader>
<CardContent className="flex items-center justify-center">
<img
src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTrmY1DyC4CYWTK_Bhn6qQygwQJW0UQgXn-ew&usqp=CAU"
className="rounded-l-[40%] rounded-r-[40%] "
/>
</CardContent>
</Card>
<Card className="bg-secondary shadow-[rgba(50,50,93,0.25)_0px_6px_12px_-2px,_rgba(0,0,0,0.3)_0px_3px_7px_-3px] drop-shadow-sm">
<CardHeader className="pb-2 text-center font-bold">
About Me
</CardHeader>
<CardContent className="text-sm">
Hello! I'm Srikkath, your dedicated admin at Kutubi, ensuring a
seamless and enriching experience for teachers, Proposals, and
parents. Feel free to reach out for any assistance or feedback
</CardContent>
</Card>
<Card className="bg-secondary shadow-[rgba(50,50,93,0.25)_0px_6px_12px_-2px,_rgba(0,0,0,0.3)_0px_3px_7px_-3px] drop-shadow-sm">
<CardHeader className="pb-2 text-center font-bold">
Last Login
</CardHeader>
<CardContent className="text-center text-sm">
12 Aug 2022 9:30 AM
</CardContent>
</Card>
</div>
{/* contact information */}
<Card className=" col-span-1 bg-secondary shadow-[rgba(50,50,93,0.25)_0px_6px_12px_-2px,_rgba(0,0,0,0.3)_0px_3px_7px_-3px] drop-shadow-sm lg:col-span-3">
<CardHeader className="text-xl font-bold">
Contact Information
</CardHeader>

<CardContent>
<div className="grid grid-cols-2 gap-y-4">
<div>
<p className="font-bold text-black">First Name</p>
<p className="text-muted-foreground">John</p>
</div>
<div>
<p className="font-bold text-black">Last Name</p>
<p className="text-muted-foreground">Doe</p>
</div>
<div>
<p className="font-bold text-black">User Name</p>
<p className="text-muted-foreground">John</p>
</div>
<div>
<p className="font-bold text-black">Sex</p>
<p className="text-muted-foreground">Male</p>
</div>
<div>
<p className="font-bold text-black">Position</p>
<p className="text-muted-foreground">Super Admin</p>
</div>
<div>
<p className="font-bold text-black">Department</p>
<p className="text-muted-foreground">Kutubi</p>
</div>
<div>
<p className="font-bold text-black">Contact Email</p>
<p className="text-muted-foreground">[email protected]</p>
</div>
<div>
<p className="font-bold text-black">Contact Number</p>
<p className="text-muted-foreground">Nil</p>
</div>
<div>
<p className="font-bold text-black">City</p>
<p className="text-muted-foreground">Dubai</p>
</div>
<div>
<p className="font-bold text-black">Language</p>
<p className="text-muted-foreground">English</p>
</div>
<div>
<p className="font-bold text-black">Date of Birth</p>
<p className="text-muted-foreground">26/4/1989</p>
</div>
<div>
<p className="font-bold text-black">Social Media</p>
<p className="text-muted-foreground">x</p>
</div>
</div>
</CardContent>
</Card>
</div>
<div className="flex items-center justify-center"></div>
<ProposalFeedTable
users={users}
page={page}
totalUsers={totalUsers}
pageCount={pageCount}
/>
</div>
);
}
Loading

0 comments on commit bcf68e0

Please sign in to comment.