-
Notifications
You must be signed in to change notification settings - Fork 3
feat(profile): Add social and academic profile section #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Ritesh-Udgata
wants to merge
5
commits into
bphcerp:main
Choose a base branch
from
Ritesh-Udgata:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
49a7eb2
feat(profile): Add social and academic profile section
Ritesh-Udgata 5cb0902
fix(profile): Fix build issues and update toast implementation
Ritesh-Udgata f9b1c30
fix(profile,ui): reduce toast delay to 5s, use isPending, reset form …
Ritesh-Udgata b5e267f
Profile page fix
Ritesh-Udgata ca53a35
Merge branch 'bphcerp:main' into main
Ritesh-Udgata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
client/src/components/profile/SocialAcademicProfile.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||
| import { Link, GraduationCap } from "lucide-react"; | ||
| import { useForm } from "react-hook-form"; | ||
| import { zodResolver } from "@hookform/resolvers/zod"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; | ||
| import { toast } from "sonner"; | ||
| import { api } from "@/lib/api"; | ||
| import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; | ||
| import * as z from "zod"; | ||
|
|
||
| const socialProfileSchema = z.object({ | ||
| linkedin: z.string().url("Please enter a valid LinkedIn URL").optional().or(z.literal("")), | ||
| orchidID: z.string().optional(), | ||
| scopusID: z.string().optional(), | ||
| googleScholar: z.string().url("Please enter a valid Google Scholar URL").optional().or(z.literal("")), | ||
| }); | ||
|
|
||
| type SocialProfileFormData = z.infer<typeof socialProfileSchema>; | ||
|
|
||
| const SocialAcademicProfile = () => { | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| const { data: profileData, isLoading } = useQuery({ | ||
| queryKey: ["user-profile"], | ||
| queryFn: async () => { | ||
| const response = await api.get("/profile"); | ||
| return response.data; | ||
| }, | ||
| }); | ||
|
|
||
| const form = useForm<SocialProfileFormData>({ | ||
| resolver: zodResolver(socialProfileSchema), | ||
| defaultValues: { | ||
| linkedin: profileData?.linkedin || "", | ||
| orchidID: profileData?.orchidID || "", | ||
| scopusID: profileData?.scopusID || "", | ||
| googleScholar: profileData?.googleScholar || "", | ||
| }, | ||
| }); | ||
|
|
||
| const updateProfileMutation = useMutation({ | ||
| mutationFn: async (data: SocialProfileFormData) => { | ||
| return api.put("/profile/edit", data); | ||
| }, | ||
| onSuccess: () => { | ||
| toast.success("Social/academic profile updated successfully"); | ||
| queryClient.invalidateQueries({ queryKey: ["user-profile"] }); | ||
| }, | ||
| onError: () => { | ||
| toast.error("Failed to update profile. Please try again."); | ||
| }, | ||
| }); | ||
|
|
||
| const onSubmit = (data: SocialProfileFormData) => { | ||
| updateProfileMutation.mutate(data); | ||
| }; | ||
|
|
||
| if (isLoading) { | ||
| return <div>Loading...</div>; | ||
| } | ||
|
|
||
| return ( | ||
| <Card> | ||
| <CardHeader> | ||
| <CardTitle className="flex items-center gap-2"> | ||
| <Link className="h-5 w-5" /> | ||
| <GraduationCap className="h-5 w-5" /> | ||
| Social & Academic Profiles | ||
| </CardTitle> | ||
| <p className="text-sm text-gray-600"> | ||
| Connect your professional and academic profiles | ||
| </p> | ||
| </CardHeader> | ||
| <CardContent> | ||
| <Form {...form}> | ||
| <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> | ||
| <FormField | ||
| control={form.control} | ||
| name="linkedin" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>LinkedIn Profile</FormLabel> | ||
| <FormControl> | ||
| <Input placeholder="https://linkedin.com/in/yourusername" {...field} /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <FormField | ||
| control={form.control} | ||
| name="orchidID" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>ORCID ID</FormLabel> | ||
| <FormControl> | ||
| <Input placeholder="0000-0000-0000-0000" {...field} /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <FormField | ||
| control={form.control} | ||
| name="scopusID" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Scopus ID</FormLabel> | ||
| <FormControl> | ||
| <Input placeholder="Your Scopus ID" {...field} /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <FormField | ||
| control={form.control} | ||
| name="googleScholar" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Google Scholar Profile</FormLabel> | ||
| <FormControl> | ||
| <Input placeholder="https://scholar.google.com/citations?user=..." {...field} /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <Button | ||
| type="submit" | ||
| className="w-full" | ||
| disabled={updateProfileMutation.isLoading} | ||
| > | ||
| {updateProfileMutation.isLoading ? "Updating..." : "Save Changes"} | ||
Radian6405 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Radian6405 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Button> | ||
| </form> | ||
| </Form> | ||
| </CardContent> | ||
| </Card> | ||
| ); | ||
| }; | ||
|
|
||
| export default SocialAcademicProfile; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import * as React from "react" | ||
| import * as ToastPrimitives from "@radix-ui/react-toast" | ||
| import { cva, type VariantProps } from "class-variance-authority" | ||
| import { X } from "lucide-react" | ||
|
|
||
| import { cn } from "@/lib/utils" | ||
|
|
||
| const ToastProvider = ToastPrimitives.Provider | ||
|
|
||
| const ToastViewport = React.forwardRef< | ||
| React.ElementRef<typeof ToastPrimitives.Viewport>, | ||
| React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport> | ||
| >(({ className, ...props }, ref) => ( | ||
| <ToastPrimitives.Viewport | ||
| ref={ref} | ||
| className={cn( | ||
| "fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| ToastViewport.displayName = ToastPrimitives.Viewport.displayName | ||
|
|
||
| const toastVariants = cva( | ||
| "group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full", | ||
| { | ||
| variants: { | ||
| variant: { | ||
| default: "border bg-background", | ||
| destructive: | ||
| "destructive group border-destructive bg-destructive text-destructive-foreground", | ||
| }, | ||
| }, | ||
| defaultVariants: { | ||
| variant: "default", | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| const Toast = React.forwardRef< | ||
| React.ElementRef<typeof ToastPrimitives.Root>, | ||
| React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & | ||
| VariantProps<typeof toastVariants> | ||
| >(({ className, variant, ...props }, ref) => { | ||
| return ( | ||
| <ToastPrimitives.Root | ||
| ref={ref} | ||
| className={cn(toastVariants({ variant }), className)} | ||
| {...props} | ||
| /> | ||
| ) | ||
| }) | ||
| Toast.displayName = ToastPrimitives.Root.displayName | ||
|
|
||
| const ToastAction = React.forwardRef< | ||
| React.ElementRef<typeof ToastPrimitives.Action>, | ||
| React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action> | ||
| >(({ className, ...props }, ref) => ( | ||
| <ToastPrimitives.Action | ||
| ref={ref} | ||
| className={cn( | ||
| "inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| ToastAction.displayName = ToastPrimitives.Action.displayName | ||
|
|
||
| const ToastClose = React.forwardRef< | ||
| React.ElementRef<typeof ToastPrimitives.Close>, | ||
| React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close> | ||
| >(({ className, ...props }, ref) => ( | ||
| <ToastPrimitives.Close | ||
| ref={ref} | ||
| className={cn( | ||
| "absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600", | ||
| className | ||
| )} | ||
| toast-close="" | ||
| {...props} | ||
| > | ||
| <X className="h-4 w-4" /> | ||
| </ToastPrimitives.Close> | ||
| )) | ||
| ToastClose.displayName = ToastPrimitives.Close.displayName | ||
|
|
||
| const ToastTitle = React.forwardRef< | ||
| React.ElementRef<typeof ToastPrimitives.Title>, | ||
| React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title> | ||
| >(({ className, ...props }, ref) => ( | ||
| <ToastPrimitives.Title | ||
| ref={ref} | ||
| className={cn("text-sm font-semibold", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| ToastTitle.displayName = ToastPrimitives.Title.displayName | ||
|
|
||
| const ToastDescription = React.forwardRef< | ||
| React.ElementRef<typeof ToastPrimitives.Description>, | ||
| React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description> | ||
| >(({ className, ...props }, ref) => ( | ||
| <ToastPrimitives.Description | ||
| ref={ref} | ||
| className={cn("text-sm opacity-90", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| ToastDescription.displayName = ToastPrimitives.Description.displayName | ||
|
|
||
| type ToastProps = React.ComponentPropsWithoutRef<typeof Toast> | ||
|
|
||
| type ToastActionElement = React.ReactElement<typeof ToastAction> | ||
|
|
||
| export { | ||
| type ToastProps, | ||
| type ToastActionElement, | ||
| ToastProvider, | ||
| ToastViewport, | ||
| Toast, | ||
| ToastTitle, | ||
| ToastDescription, | ||
| ToastClose, | ||
| ToastAction, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { useTheme } from "next-themes" | ||
|
|
||
| import { ToastProvider } from "@/components/ui/toast" | ||
| import { Toaster as Sonner } from "sonner" | ||
|
|
||
| export function Toaster() { | ||
| const { theme = "system" } = useTheme() | ||
|
|
||
| return ( | ||
| <ToastProvider> | ||
| <Sonner | ||
| theme={theme as "light" | "dark" | "system"} | ||
| className="toaster group" | ||
| toastOptions={{ | ||
| classNames: { | ||
| toast: | ||
| "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg", | ||
| description: "group-[.toast]:text-muted-foreground", | ||
| actionButton: | ||
| "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground", | ||
| cancelButton: | ||
| "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground", | ||
| }, | ||
| }} | ||
| /> | ||
| </ToastProvider> | ||
| ) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The form default values are set during initialization but won't update when
profileDataloads asynchronously. Use theresetmethod in auseEffectto update form values after data loads, or use thevaluesprop instead ofdefaultValues.