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

[Feature] Enable search by participant name and display name in admin panel #217

Open
GhostOf0days opened this issue Jan 21, 2024 · 0 comments
Labels
enhancement New feature or request sudo Admin page functionality

Comments

@GhostOf0days
Copy link
Member

GhostOf0days commented Jan 21, 2024

Description

Will lead to faster prize distribution. Likely requires changes in the backend as well to optimize loading time. It is possible at the moment by adding properties to data, but will result in much slower loading of admin panel data.

Here is a rough, unoptimized example (added to /src/components/admin/ParticipantTable/index.tsx near line 181) of where slower loading time will occur by directly adding fullName:

  const fetchFullName = async (participantId: any) => {
    try {
      const { data } = await dispatch(actions.user.getProfile(participantId))
      const fullName = [data.firstName, data.middleName, data.lastName].filter(Boolean).join(' ')
      return fullName
    } catch (err) {
      console.error(err)
    }
  }
  
    useEffect(() => {
    const getParticipants = async () => {
      setLoading(true)
      try {
        const { data } = (await dispatch(actions.user.getParticipants())) as {
          data: Participant[]
        }

        const dataWithFullNames = await Promise.all(data.map(async participant => {
          const fullName = await fetchFullName(participant._id)
          return { ...participant, fullName }
        }))
        
        dataWithFullNames.sort((a, b) => {
          const statusComp = a.status.localeCompare(b.status)
          if (statusComp !== 0) {
            return statusComp
          }
          return a.email.localeCompare(b.email)
        })
        setParticipants(dataWithFullNames)

Even this would require additional fidgeting with types to work for the search. So again, the easiest solution is also changing the backend.

@GhostOf0days GhostOf0days added enhancement New feature or request sudo Admin page functionality labels Jan 21, 2024
@GhostOf0days GhostOf0days changed the title [Feature] Enable search by participant name and display name [Feature] Enable search by participant name and display name in admin panel Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sudo Admin page functionality
Projects
None yet
Development

No branches or pull requests

1 participant