Skip to content

Commit

Permalink
Merge branch 'andrew' into 7-create-a-hacker-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ashrithathmaram committed Jan 26, 2024
2 parents 9ad5914 + f97c0d7 commit b4fe663
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
63 changes: 32 additions & 31 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use client"

import AcmeLogo from '@/app/ui/acme-logo';
import LoginForm from '@/app/ui/login-form';
import { getSelf, getUsers } from '@/app/lib/data';
import { UpdateSelf, getSelf, getUsers } from '@/app/lib/data';
import { useState, useEffect } from 'react';
import { AvatarImage, AvatarInitials, Avatar } from "@/app/dashboard/components/avatar"
import { CardTitle, CardDescription, CardHeader, CardContent, CardFooter, Card } from "@/app/dashboard/components/card"
Expand All @@ -13,7 +11,7 @@ import OrganizerView from "@/app/dashboard/views/organizerView"
import DirectorView from "@/app/dashboard/views/directorView"


import { SubmitHandler, useForm } from "react-hook-form";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from 'zod';

Expand All @@ -23,8 +21,6 @@ export default function Dashboard() {

const UserUpdateSchema = z.object({
email: z.string().email(),
role: z.string(),
registration_status: z.string(),

first_name: z.string(),
last_name: z.string(),
Expand All @@ -33,7 +29,7 @@ export default function Dashboard() {
major: z.string(),
short_answer: z.string(),
shirt_size: z.string(),
hackathon_count: z.string(),
hackathon_count: z.number(),
dietary_restrictions: z.string(),
special_needs: z.string(),
date_of_birth: z.string(),
Expand All @@ -43,37 +39,42 @@ export default function Dashboard() {
level_of_study: z.string(),
country_of_residence: z.string(),
ethnicity: z.string(),
phone_number: z.string(),
phone_number: z.number({
invalid_type_error: "Enter Phone Number in the format 1234567890",
}).min(1000000000).max(9999999999),
how_you_heard_about_hackru: z.string(),
reasons: z.string(),

});

type UserUpdate = z.infer<typeof UserUpdateSchema>;

const {
register,
handleSubmit,
formState: { errors },
} = useForm<UserUpdate>({
resolver: zodResolver(UserUpdateSchema),
});

const onSubmit: SubmitHandler<UserUpdate> = (data: any) => console.log(data);



const {register,handleSubmit,reset, formState: { errors },} = useForm<UserUpdate>({resolver: zodResolver(UserUpdateSchema),defaultValues: userData,});

const onSubmit = (data: UserUpdate) => {
console.log("Hi");
UpdateSelf(data);
}

useEffect(() => {
async function fetchUser() {
try {
const data = await getSelf();
setUserData(data);
// setLoading(false);
} catch (error) {
console.log(error);
// setLoading(false);
}
async function fetchUser() {
try {
const data = await getSelf();
setUserData(data);
console.log(userData);
// setLoading(false);
} catch (error) {
console.log(error);
// setLoading(false);
}

fetchUser();
}

fetchUser();
reset()

}, []);

if (userData?.role.hacker){
Expand Down Expand Up @@ -243,12 +244,12 @@ export default function Dashboard() {
</div>
<div className="space-y-2">
<Label htmlFor="hackathon-count">Hackathon Count</Label>
<Input type="number" id="hackathon-count" value={userData?.hackathon_count} {...register("hackathon_count")} onChange={(e) => setUserData({...userData, hackathon_count: e.target.value})}/>
<Input type="number" id="hackathon-count" value={userData?.hackathon_count} {...register("hackathon_count", { valueAsNumber: true })} onChange={(e) => setUserData({...userData, hackathon_count: e.target.value})}/>
{errors.hackathon_count && (<p className="text-xs italic text-red-500 mt-2">{errors.hackathon_count?.message}</p>)}
</div>
<div className="space-y-2">
<Label htmlFor="phone-number">Phone #</Label>
<Input type="number" id="phone-number" value={userData?.phone_number} {...register("phone_number")} onChange={(e) => setUserData({...userData, phone_number: e.target.value})}/>
<Input type="number" id="phone-number" value={userData?.phone_number} {...register("phone_number", { valueAsNumber: true })} onChange={(e) => setUserData({...userData, phone_number: e.target.value})}/>
{errors.phone_number && (<p className="text-xs italic text-red-500 mt-2">{errors.phone_number?.message}</p>)}
</div>
<div className="space-y-2">
Expand All @@ -268,7 +269,7 @@ export default function Dashboard() {
</div>
</CardContent>
<CardFooter>
<Button type = "submit" className="ml-auto" onClick={()=>console.log("submit button")}>Save</Button>
<Button type = "submit" className="ml-auto" onClick={()=>console.log(errors)}>Save</Button>
</CardFooter>
</form>
</Card>
Expand Down
11 changes: 11 additions & 0 deletions app/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,14 @@ export async function getUsers(){


}

export async function UpdateSelf(data:any){
console.log(data);
console.log("updating self");
}

export async function UpdateUser(){
//double check that the whoever is logged in and is sending this request is an admin
console.log("updaing a user");
}

0 comments on commit b4fe663

Please sign in to comment.