Skip to content
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

Joni/feature/96-add-cms-for-members-page #101

Merged
merged 75 commits into from
Oct 7, 2024

Conversation

Jonroi
Copy link
Collaborator

@Jonroi Jonroi commented Sep 25, 2024

Add starapi calls and implement attributes to sectionMembers component
Add nude CSS for later designing

…uidance.

- Adopted Function Component pattern to streamline component structure.
…am members.

- Implemented fetchTeamMembers function to retrieve team member data from the API.
…kend API.

- Implemented grouping logic to organize members by role in the SectionMembers component.
- Enhanced UI integration by displaying fetched data dynamically within the application.
…ons.

- Updated the structure of MemberComponent to include a flex container for icons.
- Adjusted CSS to ensure icons are aligned in a row while TaskText is displayed below.
Cleaning & Documentation
Add Logo paths via envHelper
Add documentation
Adjust Arrange for part and role
@Jonroi Jonroi self-assigned this Sep 25, 2024
*/
import { Member, Department } from '@/entities/Member/model/types/types';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my fault that I didn't add the rules about imports and exports earlier. But please now read and correct according to this wiki: https://github.com/Alt-Org/Altzone-WebPages/wiki/Project-Structure#relative-and-absolute-imports

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make in rtk style and dont forget to connect it to app/_providers/StoreProvider , you can see examples in other enties.

Here's how it might look:

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { envHelper } from '@/shared/const/envHelper';
import { Team } from '../model/types';
import { mapMembers, mapDepartments } from './mappers';

export const membersApi = createApi({
  reducerPath: 'membersApi',
  baseQuery: fetchBaseQuery({ baseUrl: envHelper.strapiApiUrl }),
  endpoints: (builder) => ({
    getTeams: builder.query<Team[], string>({
      // Since this is a GET request, we only need to define the query URL
      query: (locale = 'en') => {
        // Define the Strapi locale based on the input locale
        const strapiLocale = locale === 'fi' ? 'fi-FI' : 'en';
        // Build the API request URL for a GET request
        return `/teams?locale=${strapiLocale}&populate=departments.localizations,members.Logo,departments.members.Logo`;
      },
      transformResponse: (response: any, meta, locale: string) => {
        // Map the response data to the appropriate types
        const teams: Team[] = response.data.map((item: any) => {
          // Map team-level members (members who are not part of a specific department)
          let members = mapMembers(item.attributes.members?.data || []);
          
          // Map departments associated with the team
          const departments = mapDepartments(
            item.attributes.departments?.data || [],
            locale === 'fi' ? 'fi-FI' : 'en'
          );

          // Collect all member IDs that are assigned to departments
          const departmentMemberIds = departments.flatMap((dept) =>
            dept.members.map((member) => member.id)
          );

          // Filter out members that are already in a department from team-level members
          members = members.filter(
            (member) => !departmentMemberIds.includes(member.id)
          );

          // Return the mapped team with its members and departments
          return {
            id: item.id,
            name: item.attributes.name,
            members,
            departments,
          };
        });

        // Define the sort order for teams based on the locale
        const orderEn = [
          'Game Design',
          'Mentoring',
          'Administration',
          'Development',
          'Marketing',
        ];

        const orderFi = [
          'Pelit Suunnittelu',
          'Mentorointi',
          'Hallinto',
          'Kehitys',
          'Markkinointi',
        ];

        const order = locale === 'fi' ? orderFi : orderEn;

        // Sort teams based on the predefined order
        return teams.sort(
          (a: Team, b: Team) => order.indexOf(a.name) - order.indexOf(b.name)
        );
      },
    }),
  }),
});

export const { useGetTeamsQuery } = membersApi;

Dont forget to export this hook via public api (see https://github.com/Alt-Org/Altzone-WebPages/wiki/Project-Structure#between-modules-absolute-imports-via-indexts)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think you just need to do this mapping inside "transformResponse" and pass it out through a hook that generates rtk query like "useGetTeamsQuery"

@leolabdev leolabdev mentioned this pull request Oct 4, 2024
5 tasks
…s-for-members-page

# Conflicts:
#	frontend-next-migration/src/preparedPages/MembersPage/ui/MembersPage.module.scss
#	frontend-next-migration/src/preparedPages/MembersPage/ui/MembersPage.tsx
#	frontend-next-migration/src/shared/const/envHelper.ts
#	frontend-next-migration/src/widgets/SectionMembers/ui/SectionMembers.module.scss
#	frontend-next-migration/src/widgets/SectionMembers/ui/SectionMembers.tsx
The language parameter `lng` was redundant and has been removed from the `useClientTranslation` hook call. This change simplifies the code and eliminates potential confusion regarding language handling.
@leolabdev
Copy link
Member

pay attention also on
image

@Jonroi Jonroi requested a review from leolabdev October 5, 2024 17:06
Reorganize import paths to use relative paths for `Team` and mappers functions. This aligns with the project's import conventions and improves maintainability.
Updated the import statement to use relative path '../model/types/types' instead of absolute path '@/entities/Member/model/types/types'. This change ensures compatibility with the project's module resolution configuration.
Updated relative import paths for 'Member' and 'Department' types to ensure better module resolution. Adjusted import order for cleaner and more consistent code organization.
Update the MemberItem component to use a more accurate type for the member links by excluding the "id" property. This change ensures type safety and prevents potential runtime errors when accessing link properties.
Introduce Strapi API to the project by creating `strapiApi` in `strapiApi.ts` and updating state schema and store configuration. This ensures the Strapi API can now be utilized alongside the existing game API to manage different data interactions.
Replaced `createApi` with `strapiApi.injectEndpoints` to streamline API handling. This change reduces redundancy by utilizing the shared `strapiApi` configuration, simplifying the codebase and ensuring consistency in endpoint management.
Exporting useGetTeamsQuery enables team data fetching in components utilizing the Member entity. This change simplifies importing necessary hooks directly from the member module.
Consolidate imports from '@/entities/Member' to enhance readability and maintainability. This change groups related imports together, reducing redundancy and improving code organization.
@leolabdev leolabdev self-assigned this Oct 7, 2024
This commit introduces NEXT_PUBLIC_STRAPI_API_URL and NEXT_PUBLIC_STRAPI_HOST to the CI workflow. These additional environment variables are necessary for testing and building Strapi-dependent features.
@leolabdev leolabdev merged commit 537897d into dev Oct 7, 2024
@leolabdev leolabdev deleted the joni/feature/96-add-cms-for-members-page branch October 7, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants