From 6853ab979ca9671197e668e6052898e727246126 Mon Sep 17 00:00:00 2001 From: ubungmeister Date: Sun, 29 Oct 2023 11:09:12 +0100 Subject: [PATCH 1/6] draft --- next.config.js | 10 +- src/app/api/member/member.ts | 71 +++++++++++- src/app/api/member/member.type.ts | 18 +-- src/app/member-profile/page.tsx | 82 ++++++++++++++ src/library/molecules/cards/ProfileCard.tsx | 2 +- src/pages/_app.tsx | 11 ++ src/pages/member-profile/[id].tsx | 115 ++++++++++++++++++++ 7 files changed, 295 insertions(+), 14 deletions(-) create mode 100644 src/app/member-profile/page.tsx create mode 100644 src/pages/_app.tsx create mode 100644 src/pages/member-profile/[id].tsx diff --git a/next.config.js b/next.config.js index e34c6b5..2c05107 100644 --- a/next.config.js +++ b/next.config.js @@ -41,7 +41,15 @@ const nextConfig = { ]; }, images: { - domains: ["unsplash.com", "images.unsplash.com", "res.cloudinary.com"], + domains: [ + "unsplash.com", + "images.unsplash.com", + "res.cloudinary.com", + "mingly.cz", + "wikipedia.org", + "gravatar.com", + "www.gravatar.com", + ], }, images: { remotePatterns: [ diff --git a/src/app/api/member/member.ts b/src/app/api/member/member.ts index 3efd193..6d7a553 100644 --- a/src/app/api/member/member.ts +++ b/src/app/api/member/member.ts @@ -23,9 +23,8 @@ import { // TODO: Invalidate cache after PUT requests export const getMembers = async (options: Record, _requestParams: IMembersRequestParams) => { - try { - const session = await getServerSession(authOptions); - if (!session) return; + const session = await getServerSession(authOptions); + if (!session) return; const response = await http.get(`${process.env.WP_API_URL}/members`, { data: _requestParams, @@ -61,6 +60,72 @@ export const getMemberById = async ( } }; +export const getMemberID = async (id: number) => { + // const session = await getServerSession(authOptions); + // if (!session) return; + try { + const member = await fetch(`${process.env.WP_API_URL}/members/${id}`); + return (await member.json()) as IMemberResponse; + } catch (error) { + // TODO: log error + return; + } +}; +export const getProfile = async (id: number) => {}; + +export const getProfileData = async (id: number) => { + const params = new URLSearchParams({ + user_id: id.toString(), + context: "view", + fetch_field_data: "true", + }); + + const response = await fetch(`${process.env.WP_API_URL}/xprofile/fields?${params.toString()}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + if (!response.ok) { + throw new Error(`Failed to fetch profile data: ${response.statusText}`); + } + + // Parse and return the JSON data + return await response.json(); +}; + +export const getMemeberProfile = async (id: number) => { + console.log("id", id); + try { + const testResponse = await fetch(`${process.env.WP_API_URL}/xprofile/4/data/${id}`); + const sexResponse = await fetch(`${process.env.WP_API_URL}/xprofile/4/data/${id}`); + const ageResponse = await fetch(`${process.env.WP_API_URL}/xprofile/2/data/${id}`); + const regionResponse = await fetch(`${process.env.WP_API_URL}/xprofile/9/data/${id}`); + const cityResponse = await fetch(`${process.env.WP_API_URL}/xprofile/5/data/${id}`); + const hobbiesResponse = await fetch(`${process.env.WP_API_URL}/xprofile/182/data/${id}`); + const statusResponse = await fetch(`${process.env.WP_API_URL}/xprofile/45/data/${id}`); + + const sex = await sexResponse.json(); + const age = await ageResponse.json(); + const region = await regionResponse.json(); + const city = await cityResponse.json(); + const hobbies = await hobbiesResponse.json(); + const status = await statusResponse.json(); + + return { + sex, + age, + region, + city, + hobbies, + status, + }; + } catch (error) { + // TODO: log error + return; + } +}; + // FIXME: The updateMember() does not seem to be working. Postman can change data, but this request not (but still the received status code is 200). // TODO: Is the updateMember() function needed? Fix or remove. export const updateMember = async ( diff --git a/src/app/api/member/member.type.ts b/src/app/api/member/member.type.ts index 0f57115..36b0fae 100644 --- a/src/app/api/member/member.type.ts +++ b/src/app/api/member/member.type.ts @@ -14,7 +14,7 @@ export interface IMemberResponse { roles?: unknown[]; // Roles assigned to the member. capabilities?: Record; // All capabilities assigned to the member. extra_capabilities?: Record; // All capabilities assigned to the member. - xprofile?: Xprofile; // Member xProfile groups and its fields. + xprofile?: any[]; // Member xProfile groups and its fields. friendship_status?: boolean; // Whether the logged in user has a friendship relationship with the fetched user. friendship_status_slug?: "is_friend" | "not_friends" | "pending" | "awaiting_response"; // Slug of the friendship relationship status the logged in user has with the fetched user. last_activity?: Record; // Last date the member was active on the site (object properties: timediff, date and date_gmt). @@ -27,23 +27,23 @@ export interface IMemberResponse { } export type Xprofile = { groups: { [key: string]: Group }; -} +}; export type Group = { - name: string; + name: string; fields: { [key: string]: Field }; -} +}; export type Field = { - name: string; + name: string; value: Value; -} +}; export type Value = { - raw: string; + raw: string; unserialized: string[]; - rendered: string; -} + rendered: string; +}; /** * GET /buddypress/v1/members * https://developer.buddypress.org/bp-rest-api/reference/members/#list-members diff --git a/src/app/member-profile/page.tsx b/src/app/member-profile/page.tsx new file mode 100644 index 0000000..dc8f353 --- /dev/null +++ b/src/app/member-profile/page.tsx @@ -0,0 +1,82 @@ +import React from "react"; +import CardContainer from "library/atoms/CardContainer"; +import Image from "next/image"; + +export type MemberDetailsProps = { + name: string; + profilePhoto: any; + state: string; + gender: string; + age: number; + location: string; + hobby?: Array; + memberData?: any; + test?: any; +}; + +export default function MemberProfile({ + name, + profilePhoto, + state, + gender, + age, + location, + hobby, + test, +}: MemberDetailsProps) { + console.log("test", test); + const profilePhotoUrl = profilePhoto.slice(0, 4) === "http" ? profilePhoto : `https:${profilePhoto}`; + return ( +
+ {/* */} +
+
+ User photo +
+
+
@{name || "No name"}
+
{`${gender || "No gender"}, ${age || "No age"} let`}
+
{location || "No location"}
+
+
+

+ Ahoj, jsem Anna, jsem vášnivou fotografkou. Mým největším koníčkem je však cestování. Miluji objevování + nových kultur, poznávání neznámých míst a ochutnávání místních specialit... +

+
+
+

Par zalib:

+
    + {hobby?.slice(0, 4).map((element, index) =>
  • {element}
  • )} +
+
+
Přečíst víc o uživateli
+
+
31 přátel
+
+

Přidat mezi přátele

+

Do oblíbených

+
+
+
+ {/*
*/} + +
Společní přátelé
+
+ User photo +
+
Prohlédnout vše
+
+
Nahlásit profil
+ +
+ ); +} diff --git a/src/library/molecules/cards/ProfileCard.tsx b/src/library/molecules/cards/ProfileCard.tsx index 0b58bdc..5efe161 100644 --- a/src/library/molecules/cards/ProfileCard.tsx +++ b/src/library/molecules/cards/ProfileCard.tsx @@ -16,7 +16,7 @@ type Props = { gender: string; age: number; location: string; - status: "seznamuji se"; + status: string; tags: string[]; className?: string; }; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx new file mode 100644 index 0000000..9116ba9 --- /dev/null +++ b/src/pages/_app.tsx @@ -0,0 +1,11 @@ +import "../app/globals.css"; +import { AppProps } from "next/app"; +import RootLayout from "../app/layout"; + +export default function MyApp({ Component, pageProps }: AppProps) { + return ( +
+ +
+ ); +} diff --git a/src/pages/member-profile/[id].tsx b/src/pages/member-profile/[id].tsx new file mode 100644 index 0000000..30f8f5a --- /dev/null +++ b/src/pages/member-profile/[id].tsx @@ -0,0 +1,115 @@ +import { getMemberID, getMemeberProfile, getProfileData } from "../../app/api/member/member"; +import MemberProfile from "../../app/member-profile/page"; +import "../../app/globals.css"; +import { MemberDetailsProps } from "../../app/member-profile/page"; + +function FriendDetails({ + name, + profilePhoto, + state, + gender, + age, + location, + hobby, + memberData, + test, +}: MemberDetailsProps) { + return ( +
+ +
+ ); +} + +export async function getServerSideProps(context: any) { + const memberId = Number(context.params?.id); + + try { + const test = (await getProfileData(memberId)) as any; + console.log("test", test); + + const memberData = (await getMemberID(memberId)) as any; + if (!memberData) return { notFound: true }; + + const medialonek = test.find(item => item.name === "Medailonek").description.rendered; + console.log("here", medialonek); + + const getFieldByName = (groupName: string, fieldName: string, xprofile: any) => { + let foundField = ""; + Object.values(xprofile.groups).forEach((group: any) => { + if (group.name === groupName) { + const field = Object.values(group.fields).find((f: any) => f.name === fieldName) as { + value: { raw: string }; + }; + if (field && field.value) { + foundField = field.value.raw; + } + } + }); + return foundField; + }; + + const getArrayByName = (groupName: string, fieldName: string, xprofile: any) => { + let foundArray = [] as Array; + Object.values(xprofile.groups).forEach((group: any) => { + if (group.name === groupName) { + const field = Object.values(group.fields).find((f: any) => f.name === fieldName) as { + value: { unserialized: Array }; + }; + if (field && field.value) { + foundArray = field.value.unserialized; + } + } + }); + return foundArray; + }; + + const state = getFieldByName("Ostatní", "Status", memberData.xprofile); + const gender = getFieldByName("Základní", "Pohlaví", memberData.xprofile); + + const memberAge = getFieldByName("Základní", "Věk", memberData.xprofile); + const age = new Date().getFullYear() - new Date(memberAge).getFullYear(); + + const city = getFieldByName("Základní", "Město", memberData.xprofile); + const region = getFieldByName("Základní", "Kraj", memberData.xprofile); + const location = `${city}, ${region} kraj`; + + const hobby = getArrayByName("Koníčky", "Koníčky", memberData.xprofile); + + const name = memberData.user_login; + const profilePhoto = memberData.avatar_urls?.full || ""; + + console.log("medailonek"); + // const medailonek + + return { + props: { + test, + memberData, + name, + profilePhoto, + state, + gender, + age, + location, + hobby, + }, + }; + } catch (error) { + console.error("Error fetching member data:", error); + return { + notFound: true, + }; + } +} + +export default FriendDetails; From 0e8da8dc646bc8fcbad335b23a1ec5b2c3dea115 Mon Sep 17 00:00:00 2001 From: ubungmeister Date: Sun, 29 Oct 2023 19:24:16 +0100 Subject: [PATCH 2/6] rebased --- src/app/api/member/member.ts | 2 +- src/app/api/profile-field/profileField.ts | 1 - .../components/CreateLoveReportWizard.tsx | 93 ++++++++----------- src/app/lovereport/create/page.tsx | 1 - src/app/member-profile/page.tsx | 82 ---------------- src/app/user-profile/[id]/page.tsx | 18 ++++ .../user-profile/components/ContentBox.tsx | 33 +++++++ .../user-profile/components/InterestsBox.tsx | 7 ++ .../user-profile/components/MemberProfile.tsx | 64 +++++++++++++ src/app/user-profile/utils/index.ts | 25 +++++ src/pages/member-profile/[id].tsx | 58 +++++------- 11 files changed, 211 insertions(+), 173 deletions(-) delete mode 100644 src/app/member-profile/page.tsx create mode 100644 src/app/user-profile/[id]/page.tsx create mode 100644 src/app/user-profile/components/ContentBox.tsx create mode 100644 src/app/user-profile/components/InterestsBox.tsx create mode 100644 src/app/user-profile/components/MemberProfile.tsx create mode 100644 src/app/user-profile/utils/index.ts diff --git a/src/app/api/member/member.ts b/src/app/api/member/member.ts index 6d7a553..a8b5905 100644 --- a/src/app/api/member/member.ts +++ b/src/app/api/member/member.ts @@ -71,7 +71,6 @@ export const getMemberID = async (id: number) => { return; } }; -export const getProfile = async (id: number) => {}; export const getProfileData = async (id: number) => { const params = new URLSearchParams({ @@ -126,6 +125,7 @@ export const getMemeberProfile = async (id: number) => { } }; +export const getProfileDataById = async (id: number) => {}; // FIXME: The updateMember() does not seem to be working. Postman can change data, but this request not (but still the received status code is 200). // TODO: Is the updateMember() function needed? Fix or remove. export const updateMember = async ( diff --git a/src/app/api/profile-field/profileField.ts b/src/app/api/profile-field/profileField.ts index 55a9b7d..bf7e50f 100644 --- a/src/app/api/profile-field/profileField.ts +++ b/src/app/api/profile-field/profileField.ts @@ -61,7 +61,6 @@ export const getProfileField = async (args: { userId: number; fieldId: number }) }), headers: { Authorization: session.wpJwtToken }, }); - return response.data; }; diff --git a/src/app/lovereport/create/components/CreateLoveReportWizard.tsx b/src/app/lovereport/create/components/CreateLoveReportWizard.tsx index cfbe19f..6b71d66 100644 --- a/src/app/lovereport/create/components/CreateLoveReportWizard.tsx +++ b/src/app/lovereport/create/components/CreateLoveReportWizard.tsx @@ -1,4 +1,5 @@ "use client"; +"use client"; import StepperMenu, { StepperStep } from "library/molecules/ProgressStepper"; import { useState } from "react"; import LoveReportFieldInput from "../../common/components/LoveReportFieldInput"; @@ -17,7 +18,7 @@ type Props = { const CreateLoveReportWizard = (props: Props) => { const router = useRouter(); const [currentStep, setStep] = useState(1); - + console.log("props", props); const inputFields = props.fields.filter(e => isInput(e.type)); const maxStep = inputFields[inputFields.length - 1].group; @@ -111,59 +112,43 @@ const CreateLoveReportWizard = (props: Props) => { {e.field.placeholder} ))} -
- {currentStep > 1 ? ( -
+ {currentStep > 1 && ( + + )} + {currentStep + 1 <= maxStep && ( + + )} + + {currentStep === maxStep ? ( + + ) : ( + <> + )} ); }; diff --git a/src/app/lovereport/create/page.tsx b/src/app/lovereport/create/page.tsx index f2829b6..09acdf5 100644 --- a/src/app/lovereport/create/page.tsx +++ b/src/app/lovereport/create/page.tsx @@ -9,7 +9,6 @@ export const metadata: Metadata = { const CreateLoveReport = async () => { const result = await getLoveReportFields(); - return ( <> diff --git a/src/app/member-profile/page.tsx b/src/app/member-profile/page.tsx deleted file mode 100644 index dc8f353..0000000 --- a/src/app/member-profile/page.tsx +++ /dev/null @@ -1,82 +0,0 @@ -import React from "react"; -import CardContainer from "library/atoms/CardContainer"; -import Image from "next/image"; - -export type MemberDetailsProps = { - name: string; - profilePhoto: any; - state: string; - gender: string; - age: number; - location: string; - hobby?: Array; - memberData?: any; - test?: any; -}; - -export default function MemberProfile({ - name, - profilePhoto, - state, - gender, - age, - location, - hobby, - test, -}: MemberDetailsProps) { - console.log("test", test); - const profilePhotoUrl = profilePhoto.slice(0, 4) === "http" ? profilePhoto : `https:${profilePhoto}`; - return ( -
- {/* */} -
-
- User photo -
-
-
@{name || "No name"}
-
{`${gender || "No gender"}, ${age || "No age"} let`}
-
{location || "No location"}
-
-
-

- Ahoj, jsem Anna, jsem vášnivou fotografkou. Mým největším koníčkem je však cestování. Miluji objevování - nových kultur, poznávání neznámých míst a ochutnávání místních specialit... -

-
-
-

Par zalib:

-
    - {hobby?.slice(0, 4).map((element, index) =>
  • {element}
  • )} -
-
-
Přečíst víc o uživateli
-
-
31 přátel
-
-

Přidat mezi přátele

-

Do oblíbených

-
-
-
- {/*
*/} - -
Společní přátelé
-
- User photo -
-
Prohlédnout vše
-
-
Nahlásit profil
- -
- ); -} diff --git a/src/app/user-profile/[id]/page.tsx b/src/app/user-profile/[id]/page.tsx new file mode 100644 index 0000000..a960bcc --- /dev/null +++ b/src/app/user-profile/[id]/page.tsx @@ -0,0 +1,18 @@ +import { getProfileData, getMemberID, getMemberById } from "app/api/member/member"; +import MemberProfile from "app/user-profile/components/MemberProfile"; + +export default async function Page({ params }: { params: { id: string } }) { + const id = Number(params?.id); + + const memberData = await getMemberById(id); + + if (!memberData) return
Nebylo možné načíst data
; + + console.log("memberData", memberData); + + return ( +
+ +
+ ); +} diff --git a/src/app/user-profile/components/ContentBox.tsx b/src/app/user-profile/components/ContentBox.tsx new file mode 100644 index 0000000..661ce85 --- /dev/null +++ b/src/app/user-profile/components/ContentBox.tsx @@ -0,0 +1,33 @@ +import React from "react"; +import CardContainer from "library/atoms/CardContainer"; + +type Props = { + fields: ArrayProps[]; + groupName: string; +}; + +type ArrayProps = { + fieldName: string; + value: any; +}; + +const ContentBox = ({ fields, groupName }: Props) => { + console.log("fields", fields); + return ( + //
+ +
{groupName}
+

+ {fields.map(field => { + return ( +
    +
  • {field.value}
  • +
+ ); + })} +
+ //
+ ); +}; + +export default ContentBox; diff --git a/src/app/user-profile/components/InterestsBox.tsx b/src/app/user-profile/components/InterestsBox.tsx new file mode 100644 index 0000000..176b135 --- /dev/null +++ b/src/app/user-profile/components/InterestsBox.tsx @@ -0,0 +1,7 @@ +import React from "react"; + +const InterestsBox = () => { + return
; +}; + +export default InterestsBox; diff --git a/src/app/user-profile/components/MemberProfile.tsx b/src/app/user-profile/components/MemberProfile.tsx new file mode 100644 index 0000000..e12ca05 --- /dev/null +++ b/src/app/user-profile/components/MemberProfile.tsx @@ -0,0 +1,64 @@ +import React from "react"; +import Image from "next/image"; +import { getProfileFieldValue, getAllFieldsByGroupName } from "../utils"; +import ContentBox from "./ContentBox"; + +export type MemberDetailsProps = { + memberData?: any; +}; + +export default function MemberProfile({ memberData }: MemberDetailsProps) { + console.log("memberData", memberData); + + const profilePhotoUrl = + memberData.avatar_urls?.full.slice(0, 4) === "http" + ? memberData.avatar_urls?.full + : `https:${memberData.avatar_urls?.full}`; + + const mainInfo = getAllFieldsByGroupName("Základní", memberData.xprofile); + const gender = getProfileFieldValue(mainInfo.fields, "Pohlaví"); + const memberAge = getProfileFieldValue(mainInfo.fields, "Věk"); + const age = new Date().getFullYear() - new Date(memberAge).getFullYear(); + const city = getProfileFieldValue(mainInfo.fields, "Město"); + const region = getProfileFieldValue(mainInfo.fields, "Kraj"); + const location = `${city}, ${region} kraj`; + const description = getProfileFieldValue(mainInfo.fields, "Medailonek"); + + const hobbies = getAllFieldsByGroupName("Moje záliby", memberData.xprofile); + const sports = getAllFieldsByGroupName("Sporty", memberData.xprofile); + const appearence = getAllFieldsByGroupName("Jak vypadám", memberData.xprofile); + const relationship = getAllFieldsByGroupName("Vztah a rodina", memberData.xprofile); + const education = getAllFieldsByGroupName("Vzdělání a práce", memberData.xprofile); + const invalidity = getAllFieldsByGroupName("Hendikep", memberData.xprofile); + const lifestyle = getAllFieldsByGroupName("Životní styl", memberData.xprofile); + const preferences = getAllFieldsByGroupName("Koho hledám", memberData.xprofile); + + return ( +
+
+
+ User photo +
+
+
@{memberData.user_login || "No name"}
+
{`${gender || "No gender"}, ${age || "No age"} let`}
+
{location || "No location"}
+
+
{description}
+ + + +
Fotky...
+
+ + + + + + +
+
Falesny nebo obtezujici ucet ?
+
+
+ ); +} diff --git a/src/app/user-profile/utils/index.ts b/src/app/user-profile/utils/index.ts new file mode 100644 index 0000000..fa66b98 --- /dev/null +++ b/src/app/user-profile/utils/index.ts @@ -0,0 +1,25 @@ +export const getProfileFieldValue = (fieldsArray: any[], fieldName: string) => { + return fieldsArray.find(field => field.fieldName === fieldName)?.value; +}; + +export const getAllFieldsByGroupName = (groupName: string, xprofile: any) => { + let fields: Array<{ fieldName: string; value: any }> = []; + + Object.values(xprofile.groups).forEach((group: any) => { + if (group.name === groupName) { + Object.values(group.fields).forEach((field: any) => { + if (field && field.value) { + fields.push({ + fieldName: field.name, + value: field.value.unserialized, + }); + } + }); + } + }); + + return { + groupName: groupName, + fields: fields, + }; +}; diff --git a/src/pages/member-profile/[id].tsx b/src/pages/member-profile/[id].tsx index 30f8f5a..bff99c4 100644 --- a/src/pages/member-profile/[id].tsx +++ b/src/pages/member-profile/[id].tsx @@ -1,30 +1,22 @@ import { getMemberID, getMemeberProfile, getProfileData } from "../../app/api/member/member"; -import MemberProfile from "../../app/member-profile/page"; +import MemberProfile from "../../app/user-profile/components/MemberProfile"; import "../../app/globals.css"; -import { MemberDetailsProps } from "../../app/member-profile/page"; +import { MemberDetailsProps } from "../../app/user-profile/components/MemberProfile"; +import { getProfileFields, getProfileField } from "../../app/api/profile-field/profileField"; -function FriendDetails({ - name, - profilePhoto, - state, - gender, - age, - location, - hobby, - memberData, - test, -}: MemberDetailsProps) { +function FriendDetails({ memberData }: MemberDetailsProps) { return (
); @@ -34,15 +26,14 @@ export async function getServerSideProps(context: any) { const memberId = Number(context.params?.id); try { + // const test2 = await getProfileField({ userId: memberId, fieldId: 182 }); + // console.log("test2", test2); + const test = (await getProfileData(memberId)) as any; - console.log("test", test); const memberData = (await getMemberID(memberId)) as any; if (!memberData) return { notFound: true }; - const medialonek = test.find(item => item.name === "Medailonek").description.rendered; - console.log("here", medialonek); - const getFieldByName = (groupName: string, fieldName: string, xprofile: any) => { let foundField = ""; Object.values(xprofile.groups).forEach((group: any) => { @@ -72,7 +63,7 @@ export async function getServerSideProps(context: any) { }); return foundArray; }; - + console.log("memberData", memberData.xprofile); const state = getFieldByName("Ostatní", "Status", memberData.xprofile); const gender = getFieldByName("Základní", "Pohlaví", memberData.xprofile); @@ -88,20 +79,19 @@ export async function getServerSideProps(context: any) { const name = memberData.user_login; const profilePhoto = memberData.avatar_urls?.full || ""; - console.log("medailonek"); // const medailonek return { props: { test, memberData, - name, - profilePhoto, - state, - gender, - age, - location, - hobby, + // name, + // profilePhoto, + // state, + // gender, + // age, + // location, + // hobby, }, }; } catch (error) { From f0ae5a5ca727d0f37652b299465c553427216af5 Mon Sep 17 00:00:00 2001 From: ubungmeister Date: Thu, 2 Nov 2023 15:35:32 +0100 Subject: [PATCH 3/6] status add --- src/app/api/member/member.ts | 65 ----------- .../components/CreateLoveReportWizard.tsx | 1 - src/app/user-profile/[id]/page.tsx | 4 +- .../{MemberProfile.tsx => UserProfile.tsx} | 40 ++++++- src/pages/_app.tsx | 11 -- src/pages/member-profile/[id].tsx | 105 ------------------ 6 files changed, 36 insertions(+), 190 deletions(-) rename src/app/user-profile/components/{MemberProfile.tsx => UserProfile.tsx} (67%) delete mode 100644 src/pages/_app.tsx delete mode 100644 src/pages/member-profile/[id].tsx diff --git a/src/app/api/member/member.ts b/src/app/api/member/member.ts index a8b5905..6f4e8f3 100644 --- a/src/app/api/member/member.ts +++ b/src/app/api/member/member.ts @@ -60,71 +60,6 @@ export const getMemberById = async ( } }; -export const getMemberID = async (id: number) => { - // const session = await getServerSession(authOptions); - // if (!session) return; - try { - const member = await fetch(`${process.env.WP_API_URL}/members/${id}`); - return (await member.json()) as IMemberResponse; - } catch (error) { - // TODO: log error - return; - } -}; - -export const getProfileData = async (id: number) => { - const params = new URLSearchParams({ - user_id: id.toString(), - context: "view", - fetch_field_data: "true", - }); - - const response = await fetch(`${process.env.WP_API_URL}/xprofile/fields?${params.toString()}`, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - }); - if (!response.ok) { - throw new Error(`Failed to fetch profile data: ${response.statusText}`); - } - - // Parse and return the JSON data - return await response.json(); -}; - -export const getMemeberProfile = async (id: number) => { - console.log("id", id); - try { - const testResponse = await fetch(`${process.env.WP_API_URL}/xprofile/4/data/${id}`); - const sexResponse = await fetch(`${process.env.WP_API_URL}/xprofile/4/data/${id}`); - const ageResponse = await fetch(`${process.env.WP_API_URL}/xprofile/2/data/${id}`); - const regionResponse = await fetch(`${process.env.WP_API_URL}/xprofile/9/data/${id}`); - const cityResponse = await fetch(`${process.env.WP_API_URL}/xprofile/5/data/${id}`); - const hobbiesResponse = await fetch(`${process.env.WP_API_URL}/xprofile/182/data/${id}`); - const statusResponse = await fetch(`${process.env.WP_API_URL}/xprofile/45/data/${id}`); - - const sex = await sexResponse.json(); - const age = await ageResponse.json(); - const region = await regionResponse.json(); - const city = await cityResponse.json(); - const hobbies = await hobbiesResponse.json(); - const status = await statusResponse.json(); - - return { - sex, - age, - region, - city, - hobbies, - status, - }; - } catch (error) { - // TODO: log error - return; - } -}; - export const getProfileDataById = async (id: number) => {}; // FIXME: The updateMember() does not seem to be working. Postman can change data, but this request not (but still the received status code is 200). // TODO: Is the updateMember() function needed? Fix or remove. diff --git a/src/app/lovereport/create/components/CreateLoveReportWizard.tsx b/src/app/lovereport/create/components/CreateLoveReportWizard.tsx index 6b71d66..54426c9 100644 --- a/src/app/lovereport/create/components/CreateLoveReportWizard.tsx +++ b/src/app/lovereport/create/components/CreateLoveReportWizard.tsx @@ -18,7 +18,6 @@ type Props = { const CreateLoveReportWizard = (props: Props) => { const router = useRouter(); const [currentStep, setStep] = useState(1); - console.log("props", props); const inputFields = props.fields.filter(e => isInput(e.type)); const maxStep = inputFields[inputFields.length - 1].group; diff --git a/src/app/user-profile/[id]/page.tsx b/src/app/user-profile/[id]/page.tsx index a960bcc..766640c 100644 --- a/src/app/user-profile/[id]/page.tsx +++ b/src/app/user-profile/[id]/page.tsx @@ -1,5 +1,5 @@ -import { getProfileData, getMemberID, getMemberById } from "app/api/member/member"; -import MemberProfile from "app/user-profile/components/MemberProfile"; +import { getMemberById } from "app/api/member/member"; +import MemberProfile from "app/user-profile/components/UserProfile"; export default async function Page({ params }: { params: { id: string } }) { const id = Number(params?.id); diff --git a/src/app/user-profile/components/MemberProfile.tsx b/src/app/user-profile/components/UserProfile.tsx similarity index 67% rename from src/app/user-profile/components/MemberProfile.tsx rename to src/app/user-profile/components/UserProfile.tsx index e12ca05..5f5262a 100644 --- a/src/app/user-profile/components/MemberProfile.tsx +++ b/src/app/user-profile/components/UserProfile.tsx @@ -1,14 +1,18 @@ +"use client"; + import React from "react"; +import { useState } from "react"; import Image from "next/image"; import { getProfileFieldValue, getAllFieldsByGroupName } from "../utils"; import ContentBox from "./ContentBox"; -export type MemberDetailsProps = { +export type UserDetailsProps = { memberData?: any; }; -export default function MemberProfile({ memberData }: MemberDetailsProps) { - console.log("memberData", memberData); +export default function UserProfile({ memberData }: UserDetailsProps) { + const [showMore, setShowMore] = useState(false); + const [showAlert, setShowAlert] = useState(false); const profilePhotoUrl = memberData.avatar_urls?.full.slice(0, 4) === "http" @@ -24,10 +28,15 @@ export default function MemberProfile({ memberData }: MemberDetailsProps) { const location = `${city}, ${region} kraj`; const description = getProfileFieldValue(mainInfo.fields, "Medailonek"); + console.log("memberData", memberData); + const hobbies = getAllFieldsByGroupName("Moje záliby", memberData.xprofile); const sports = getAllFieldsByGroupName("Sporty", memberData.xprofile); const appearence = getAllFieldsByGroupName("Jak vypadám", memberData.xprofile); const relationship = getAllFieldsByGroupName("Vztah a rodina", memberData.xprofile); + + const familyState = getProfileFieldValue(relationship.fields, "Status"); + const education = getAllFieldsByGroupName("Vzdělání a práce", memberData.xprofile); const invalidity = getAllFieldsByGroupName("Hendikep", memberData.xprofile); const lifestyle = getAllFieldsByGroupName("Životní styl", memberData.xprofile); @@ -36,15 +45,23 @@ export default function MemberProfile({ memberData }: MemberDetailsProps) { return (
-
+
User photo +
+

{familyState || "Neznámý stav"}

+
@{memberData.user_login || "No name"}
{`${gender || "No gender"}, ${age || "No age"} let`}
{location || "No location"}
-
{description}
+
+

{description || "No description"}

+
+ +
+
@@ -57,7 +74,18 @@ export default function MemberProfile({ memberData }: MemberDetailsProps) {
-
Falesny nebo obtezujici ucet ?
+
+ + {showAlert && ( +
+

+ Jsi přesvědčený/á, že je tento profil falešný, nebo ses setkal/a s obtěžováním ze strany tohoto + uživatele? +

+ +
+ )} +
); diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx deleted file mode 100644 index 9116ba9..0000000 --- a/src/pages/_app.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import "../app/globals.css"; -import { AppProps } from "next/app"; -import RootLayout from "../app/layout"; - -export default function MyApp({ Component, pageProps }: AppProps) { - return ( -
- -
- ); -} diff --git a/src/pages/member-profile/[id].tsx b/src/pages/member-profile/[id].tsx deleted file mode 100644 index bff99c4..0000000 --- a/src/pages/member-profile/[id].tsx +++ /dev/null @@ -1,105 +0,0 @@ -import { getMemberID, getMemeberProfile, getProfileData } from "../../app/api/member/member"; -import MemberProfile from "../../app/user-profile/components/MemberProfile"; -import "../../app/globals.css"; -import { MemberDetailsProps } from "../../app/user-profile/components/MemberProfile"; -import { getProfileFields, getProfileField } from "../../app/api/profile-field/profileField"; - -function FriendDetails({ memberData }: MemberDetailsProps) { - return ( -
- -
- ); -} - -export async function getServerSideProps(context: any) { - const memberId = Number(context.params?.id); - - try { - // const test2 = await getProfileField({ userId: memberId, fieldId: 182 }); - // console.log("test2", test2); - - const test = (await getProfileData(memberId)) as any; - - const memberData = (await getMemberID(memberId)) as any; - if (!memberData) return { notFound: true }; - - const getFieldByName = (groupName: string, fieldName: string, xprofile: any) => { - let foundField = ""; - Object.values(xprofile.groups).forEach((group: any) => { - if (group.name === groupName) { - const field = Object.values(group.fields).find((f: any) => f.name === fieldName) as { - value: { raw: string }; - }; - if (field && field.value) { - foundField = field.value.raw; - } - } - }); - return foundField; - }; - - const getArrayByName = (groupName: string, fieldName: string, xprofile: any) => { - let foundArray = [] as Array; - Object.values(xprofile.groups).forEach((group: any) => { - if (group.name === groupName) { - const field = Object.values(group.fields).find((f: any) => f.name === fieldName) as { - value: { unserialized: Array }; - }; - if (field && field.value) { - foundArray = field.value.unserialized; - } - } - }); - return foundArray; - }; - console.log("memberData", memberData.xprofile); - const state = getFieldByName("Ostatní", "Status", memberData.xprofile); - const gender = getFieldByName("Základní", "Pohlaví", memberData.xprofile); - - const memberAge = getFieldByName("Základní", "Věk", memberData.xprofile); - const age = new Date().getFullYear() - new Date(memberAge).getFullYear(); - - const city = getFieldByName("Základní", "Město", memberData.xprofile); - const region = getFieldByName("Základní", "Kraj", memberData.xprofile); - const location = `${city}, ${region} kraj`; - - const hobby = getArrayByName("Koníčky", "Koníčky", memberData.xprofile); - - const name = memberData.user_login; - const profilePhoto = memberData.avatar_urls?.full || ""; - - // const medailonek - - return { - props: { - test, - memberData, - // name, - // profilePhoto, - // state, - // gender, - // age, - // location, - // hobby, - }, - }; - } catch (error) { - console.error("Error fetching member data:", error); - return { - notFound: true, - }; - } -} - -export default FriendDetails; From e59eb201e5a05a3d22982215f96651b0791facff Mon Sep 17 00:00:00 2001 From: ubungmeister Date: Thu, 2 Nov 2023 16:31:59 +0100 Subject: [PATCH 4/6] console log removed --- src/app/user-profile/components/InterestsBox.tsx | 7 ------- src/app/user-profile/components/UserProfile.tsx | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 src/app/user-profile/components/InterestsBox.tsx diff --git a/src/app/user-profile/components/InterestsBox.tsx b/src/app/user-profile/components/InterestsBox.tsx deleted file mode 100644 index 176b135..0000000 --- a/src/app/user-profile/components/InterestsBox.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; - -const InterestsBox = () => { - return
; -}; - -export default InterestsBox; diff --git a/src/app/user-profile/components/UserProfile.tsx b/src/app/user-profile/components/UserProfile.tsx index 5f5262a..87faf69 100644 --- a/src/app/user-profile/components/UserProfile.tsx +++ b/src/app/user-profile/components/UserProfile.tsx @@ -5,6 +5,7 @@ import { useState } from "react"; import Image from "next/image"; import { getProfileFieldValue, getAllFieldsByGroupName } from "../utils"; import ContentBox from "./ContentBox"; +import InterestsBox from "./InterestsBox"; export type UserDetailsProps = { memberData?: any; @@ -67,6 +68,8 @@ export default function UserProfile({ memberData }: UserDetailsProps) {
Fotky...
+ + From 67183e4201c8efe7897edb26691335ce67d1ecf7 Mon Sep 17 00:00:00 2001 From: ubungmeister Date: Thu, 2 Nov 2023 16:59:30 +0100 Subject: [PATCH 5/6] fields name add --- src/app/user-profile/[id]/page.tsx | 2 +- .../user-profile/components/ContentBox.tsx | 1 - .../user-profile/components/UserProfile.tsx | 54 ++++++++++++------- src/app/user-profile/utils/index.ts | 13 +++++ 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/app/user-profile/[id]/page.tsx b/src/app/user-profile/[id]/page.tsx index 766640c..1f39c88 100644 --- a/src/app/user-profile/[id]/page.tsx +++ b/src/app/user-profile/[id]/page.tsx @@ -8,7 +8,7 @@ export default async function Page({ params }: { params: { id: string } }) { if (!memberData) return
Nebylo možné načíst data
; - console.log("memberData", memberData); + console.log(memberData); return (
diff --git a/src/app/user-profile/components/ContentBox.tsx b/src/app/user-profile/components/ContentBox.tsx index 661ce85..3265295 100644 --- a/src/app/user-profile/components/ContentBox.tsx +++ b/src/app/user-profile/components/ContentBox.tsx @@ -12,7 +12,6 @@ type ArrayProps = { }; const ContentBox = ({ fields, groupName }: Props) => { - console.log("fields", fields); return ( //
diff --git a/src/app/user-profile/components/UserProfile.tsx b/src/app/user-profile/components/UserProfile.tsx index 87faf69..a64706d 100644 --- a/src/app/user-profile/components/UserProfile.tsx +++ b/src/app/user-profile/components/UserProfile.tsx @@ -1,16 +1,31 @@ "use client"; -import React from "react"; import { useState } from "react"; import Image from "next/image"; -import { getProfileFieldValue, getAllFieldsByGroupName } from "../utils"; +import { getProfileFieldValue, getAllFieldsByGroupName, calculateAge } from "../utils"; import ContentBox from "./ContentBox"; -import InterestsBox from "./InterestsBox"; export type UserDetailsProps = { memberData?: any; }; +const FIELD_NAMES = { + GENDER: "Pohlaví", + AGE: "Věk", + CITY: "Město", + REGION: "Kraj", + DESCRIPTION: "Medailonek", + FAMILY_STATE: "Status", + HOBBIES: "Moje záliby", + SPORTS: "Sporty", + APPEARENCE: "Jak vypadám", + RELATIONSHIP: "Vztah a rodina", + EDUCATION: "Vzdělání a práce", + INVALIDITY: "Hendikep", + LIFESTYLE: "Životní styl", + PREFERENCES: "Koho hledám", +}; + export default function UserProfile({ memberData }: UserDetailsProps) { const [showMore, setShowMore] = useState(false); const [showAlert, setShowAlert] = useState(false); @@ -21,27 +36,26 @@ export default function UserProfile({ memberData }: UserDetailsProps) { : `https:${memberData.avatar_urls?.full}`; const mainInfo = getAllFieldsByGroupName("Základní", memberData.xprofile); - const gender = getProfileFieldValue(mainInfo.fields, "Pohlaví"); - const memberAge = getProfileFieldValue(mainInfo.fields, "Věk"); - const age = new Date().getFullYear() - new Date(memberAge).getFullYear(); - const city = getProfileFieldValue(mainInfo.fields, "Město"); - const region = getProfileFieldValue(mainInfo.fields, "Kraj"); - const location = `${city}, ${region} kraj`; - const description = getProfileFieldValue(mainInfo.fields, "Medailonek"); + const gender = getProfileFieldValue(mainInfo.fields, FIELD_NAMES.GENDER); + const memberAge = getProfileFieldValue(mainInfo.fields, FIELD_NAMES.AGE); + const age = calculateAge(memberAge); - console.log("memberData", memberData); + const city = getProfileFieldValue(mainInfo.fields, FIELD_NAMES.CITY); + const region = getProfileFieldValue(mainInfo.fields, FIELD_NAMES.REGION); + const location = `${city}, ${region} kraj`; + const description = getProfileFieldValue(mainInfo.fields, FIELD_NAMES.DESCRIPTION); - const hobbies = getAllFieldsByGroupName("Moje záliby", memberData.xprofile); - const sports = getAllFieldsByGroupName("Sporty", memberData.xprofile); - const appearence = getAllFieldsByGroupName("Jak vypadám", memberData.xprofile); - const relationship = getAllFieldsByGroupName("Vztah a rodina", memberData.xprofile); + const hobbies = getAllFieldsByGroupName(FIELD_NAMES.HOBBIES, memberData.xprofile); + const sports = getAllFieldsByGroupName(FIELD_NAMES.SPORTS, memberData.xprofile); + const appearence = getAllFieldsByGroupName(FIELD_NAMES.APPEARENCE, memberData.xprofile); + const relationship = getAllFieldsByGroupName(FIELD_NAMES.RELATIONSHIP, memberData.xprofile); - const familyState = getProfileFieldValue(relationship.fields, "Status"); + const familyState = getProfileFieldValue(relationship.fields, FIELD_NAMES.FAMILY_STATE); - const education = getAllFieldsByGroupName("Vzdělání a práce", memberData.xprofile); - const invalidity = getAllFieldsByGroupName("Hendikep", memberData.xprofile); - const lifestyle = getAllFieldsByGroupName("Životní styl", memberData.xprofile); - const preferences = getAllFieldsByGroupName("Koho hledám", memberData.xprofile); + const education = getAllFieldsByGroupName(FIELD_NAMES.EDUCATION, memberData.xprofile); + const invalidity = getAllFieldsByGroupName(FIELD_NAMES.INVALIDITY, memberData.xprofile); + const lifestyle = getAllFieldsByGroupName(FIELD_NAMES.LIFESTYLE, memberData.xprofile); + const preferences = getAllFieldsByGroupName(FIELD_NAMES.PREFERENCES, memberData.xprofile); return (
diff --git a/src/app/user-profile/utils/index.ts b/src/app/user-profile/utils/index.ts index fa66b98..63e32c5 100644 --- a/src/app/user-profile/utils/index.ts +++ b/src/app/user-profile/utils/index.ts @@ -23,3 +23,16 @@ export const getAllFieldsByGroupName = (groupName: string, xprofile: any) => { fields: fields, }; }; + +export function calculateAge(birthDateString: string) { + const birthDate = new Date(birthDateString); + const today = new Date(); + let age = today.getFullYear() - birthDate.getFullYear(); + const monthDifference = today.getMonth() - birthDate.getMonth(); + + if (monthDifference < 0 || (monthDifference === 0 && today.getDate() < birthDate.getDate())) { + age--; + } + + return age; +} From 55320d43e39a579f7f4dc1959347b6016ee086cc Mon Sep 17 00:00:00 2001 From: ubungmeister Date: Thu, 9 Nov 2023 10:03:36 +0100 Subject: [PATCH 6/6] fix type --- src/app/api/member/member.ts | 1 + src/app/api/member/member.type.ts | 2 +- src/app/profile/page.tsx | 1 - src/app/user-profile/[id]/page.tsx | 6 ++---- src/app/user-profile/components/UserProfile.tsx | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/app/api/member/member.ts b/src/app/api/member/member.ts index 6f4e8f3..f41585f 100644 --- a/src/app/api/member/member.ts +++ b/src/app/api/member/member.ts @@ -26,6 +26,7 @@ export const getMembers = async (options: Record, _requestParam const session = await getServerSession(authOptions); if (!session) return; + try { const response = await http.get(`${process.env.WP_API_URL}/members`, { data: _requestParams, headers: { Authorization: session.wpJwtToken }, diff --git a/src/app/api/member/member.type.ts b/src/app/api/member/member.type.ts index 36b0fae..6990bde 100644 --- a/src/app/api/member/member.type.ts +++ b/src/app/api/member/member.type.ts @@ -14,7 +14,7 @@ export interface IMemberResponse { roles?: unknown[]; // Roles assigned to the member. capabilities?: Record; // All capabilities assigned to the member. extra_capabilities?: Record; // All capabilities assigned to the member. - xprofile?: any[]; // Member xProfile groups and its fields. + xprofile?: Xprofile; // Member xProfile groups and its fields. friendship_status?: boolean; // Whether the logged in user has a friendship relationship with the fetched user. friendship_status_slug?: "is_friend" | "not_friends" | "pending" | "awaiting_response"; // Slug of the friendship relationship status the logged in user has with the fetched user. last_activity?: Record; // Last date the member was active on the site (object properties: timediff, date and date_gmt). diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index 404a9ba..a3fed8f 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -12,7 +12,6 @@ export const metadata: Metadata = { export default async function Profile() { const profile = await getCurrentMember(); - if (!profile) return
Nebylo možné načíst data
; diff --git a/src/app/user-profile/[id]/page.tsx b/src/app/user-profile/[id]/page.tsx index 1f39c88..66ca0b4 100644 --- a/src/app/user-profile/[id]/page.tsx +++ b/src/app/user-profile/[id]/page.tsx @@ -1,5 +1,5 @@ import { getMemberById } from "app/api/member/member"; -import MemberProfile from "app/user-profile/components/UserProfile"; +import UserProfile from "app/user-profile/components/UserProfile"; export default async function Page({ params }: { params: { id: string } }) { const id = Number(params?.id); @@ -8,11 +8,9 @@ export default async function Page({ params }: { params: { id: string } }) { if (!memberData) return
Nebylo možné načíst data
; - console.log(memberData); - return (
- +
); } diff --git a/src/app/user-profile/components/UserProfile.tsx b/src/app/user-profile/components/UserProfile.tsx index a64706d..f568da2 100644 --- a/src/app/user-profile/components/UserProfile.tsx +++ b/src/app/user-profile/components/UserProfile.tsx @@ -29,7 +29,7 @@ const FIELD_NAMES = { export default function UserProfile({ memberData }: UserDetailsProps) { const [showMore, setShowMore] = useState(false); const [showAlert, setShowAlert] = useState(false); - + console.log(memberData); const profilePhotoUrl = memberData.avatar_urls?.full.slice(0, 4) === "http" ? memberData.avatar_urls?.full