diff --git a/src/features/Profiles/pages/ProfilePage/AboutCard/AboutCard.tsx b/src/features/Profiles/pages/ProfilePage/AboutCard/AboutCard.tsx index 6e6deaa..76aa32d 100644 --- a/src/features/Profiles/pages/ProfilePage/AboutCard/AboutCard.tsx +++ b/src/features/Profiles/pages/ProfilePage/AboutCard/AboutCard.tsx @@ -3,8 +3,7 @@ import { User } from "src/graphql" import { trimText, withHttp } from "src/utils/helperFunctions" import { FiGithub, FiGlobe, FiLinkedin, FiTwitter } from 'react-icons/fi' import Button from "src/Components/Button/Button"; -import { useToggle } from "@react-hookz/web"; -import UpdateAboutForm from "./UpdateAboutForm"; +import { PAGES_ROUTES } from "src/utils/routing"; interface Props { isOwner?: boolean; @@ -52,7 +51,6 @@ export default function AboutCard({ user, isOwner }: Props) { } ]; - const [editMode, toggleEditMode] = useToggle(false); return (
@@ -62,51 +60,44 @@ export default function AboutCard({ user, isOwner }: Props) {
- {(isOwner && !editMode) && } + {(isOwner) && }
- {editMode === true ? +
+

+ {trimText(user.name, 20)} +

- + {links.some(link => link.hasValue) &&
+ {links.filter(link => link.hasValue || isOwner).map((link, idx) => link.hasValue ? + + {link.text} + : +

+ --- +

)} +
} - : + {(user.jobTitle || isOwner) &&

+ {user.jobTitle ? user.jobTitle : "No job title added"} +

} -
-

- {trimText(user.name, 20)} -

+ {(user.lightning_address || isOwner) &&

+ {user.lightning_address ? `⚡${user.lightning_address}` : "⚡ No lightning address"} +

} - {links.some(link => link.hasValue) &&
- {links.filter(link => link.hasValue || isOwner).map((link, idx) => link.hasValue ? - - {link.text} - : -

- --- -

)} -
} - - {(user.jobTitle || isOwner) &&

- {user.jobTitle ? user.jobTitle : "No job title added"} -

} - - {(user.lightning_address || isOwner) &&

- {user.lightning_address ? `⚡${user.lightning_address}` : "⚡ No lightning address"} -

} - - {(user.bio || isOwner) &&

- {user.bio ? user.bio : "No bio added"} -

} -
- } + {(user.bio || isOwner) &&

+ {user.bio ? user.bio : "No bio added"} +

} +
) diff --git a/src/features/Profiles/pages/ProfilePage/AboutCard/UpdateAboutForm.tsx b/src/features/Profiles/pages/ProfilePage/AboutCard/UpdateAboutForm.tsx deleted file mode 100644 index c01cadf..0000000 --- a/src/features/Profiles/pages/ProfilePage/AboutCard/UpdateAboutForm.tsx +++ /dev/null @@ -1,265 +0,0 @@ -import { ComponentProps } from "react" -import { SubmitHandler, useForm } from "react-hook-form" -import Button from "src/Components/Button/Button"; -import { useUpdateProfileAboutMutation } from "src/graphql"; -import { NotificationsService } from "src/services/notifications.service"; -import AboutCard from "./AboutCard" -import * as yup from "yup"; -import { yupResolver } from "@hookform/resolvers/yup"; - -interface Props { - data: ComponentProps['user'], - onClose?: () => void; -} - -type IFormInputs = Props['data']; - -const schema: yup.SchemaOf = yup.object({ - name: yup.string().trim().required().min(2), - avatar: yup.string().url().required(), - bio: yup.string().ensure(), - email: yup.string().email().ensure(), - github: yup.string().ensure(), - jobTitle: yup.string().ensure(), - lightning_address: yup - .string() - .test({ - name: "is valid lightning_address", - test: async value => { - try { - if (value) { - const [name, domain] = value.split("@"); - const lnurl = `https://${domain}/.well-known/lnurlp/${name}`; - const res = await fetch(lnurl); - if (res.status === 200) return true; - } - return true; - } catch (error) { - return false; - } - } - }) - .ensure() - .label("lightning address"), - linkedin: yup.string().ensure(), - location: yup.string().ensure(), - twitter: yup.string().ensure(), - website: yup.string().url().ensure(), - -}).required(); - -export default function UpdateAboutForm({ data, onClose }: Props) { - - const { register, formState: { errors }, handleSubmit } = useForm({ - defaultValues: data, - resolver: yupResolver(schema), - mode: 'onBlur', - }); - - const [mutate, mutationStatus] = useUpdateProfileAboutMutation({ - onCompleted: () => { - onClose?.() - } - }); - - - - const onSubmit: SubmitHandler = data => { - mutate({ - variables: { - data: { - name: data.name, - avatar: data.avatar, - jobTitle: data.jobTitle, - bio: data.bio, - email: data.email, - github: data.github, - linkedin: data.linkedin, - lightning_address: data.lightning_address, - location: data.location, - twitter: data.twitter, - website: data.website, - } - } - }).catch(() => { - NotificationsService.error('A network error happened'); - mutationStatus.reset() - }) - }; - - return ( -
-

- Name -

-
- -
- {errors.name &&

- {errors.name.message} -

} -

- Avatar -

-
- -
- {errors.avatar &&

- {errors.avatar.message} -

} -

- Bio -

-
-