{"size": 1074, "ext": "js", "max_stars_repo_path": "components/ApplicationsList/index.js", "max_stars_repo_name": "tupuio/tupuapp", "max_stars_repo_stars_event_min_datetime": "2022-02-18T12:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T12:04:25.000Z", "max_issues_repo_path": "components/ApplicationsList/index.js", "max_issues_repo_name": "tupuio/tupuapp", "max_issues_repo_issues_event_min_datetime": "2022-02-10T22:59:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T18:10:58.000Z", "max_forks_repo_path": "components/ApplicationsList/index.js", "max_forks_repo_name": "tupuio/tupuapp", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 18, "max_forks_count": null, "avg_line_length": 24.976744186, "max_line_length": 78, "alphanum_fraction": 0.6014897579}
import { Alert, AlertIcon } from "@chakra-ui/alert";
import { SimpleGrid, Text } from "@chakra-ui/layout";
import useSWR from "swr";
import ApplicationCard from "./ApplicationCard";

const fetcher = (...args) => fetch(...args).then((res) => res.json());

const ApplicationsList = () => {
  const { data, error } = useSWR("/api/applications", fetcher);

  if (error) {
    return (
      <Alert mt={10} status="error">
        <AlertIcon />
        Error retrieving the applications. {error.toString()}
      </Alert>
    );
  }

  if (!data) {
    return <div>Loading..</div>;
  }

  if (data.records.length == 0) {
    return (
      <Text mt={10} fontWeight={700}>
        You didn&apos;t send any application for mentorship yet. Please, go to
        Find a mentor, and send your first one soon!
      </Text>
    );
  }

  return (
    <SimpleGrid mt={10} columns={1} spacing={10}>
      {data.records.map((application) => (
        <ApplicationCard key={application.id} application={application} />
      ))}
    </SimpleGrid>
  );
};

export default ApplicationsList;
