+
+
Winter Camp 2024 Recruitment Task
-
- Go to task
+
+ Go to task
);
diff --git a/pages/task/[page].tsx b/pages/task/[page].tsx
index 86f1097..2b190cc 100644
--- a/pages/task/[page].tsx
+++ b/pages/task/[page].tsx
@@ -2,7 +2,57 @@
* @todo List crew members using the endpoint you created
* @description Use tanstack/react-query or swr to fetch data from the endpoint. Prepare pagination.
*/
+import { NextPageContext } from 'next';
+import Link from 'next/link';
+
+import { CrewLayout } from '@/components/CrewLayout';
+import { CrewList } from '@/components/crew-list/CrewList';
+import { LoadingIcon } from '@/components/icons/LoadingIcon';
+import { Pagination } from '@/components/pagination/Pagination';
+import { useReactQueryPagination } from '@/lib/hooks/useReactQueryPagination';
+import { parseToNumber } from '@/lib/utils/parse-to-number';
+
+export const getServerSideProps = async ({
+ query: { page },
+}: NextPageContext) => {
+ const parsedPage = parseToNumber(page);
+ if (!parsedPage) return { notFound: true };
+ return {
+ props: {
+ page: parsedPage,
+ },
+ };
+};
export default function Task() {
- return Task;
+ const { isLoading, isError, error, data } = useReactQueryPagination();
+
+ if (isError) return ;
+ if (isLoading || !data) return ;
+
+ const { data: crew, pagination } = data;
+ return (
+
+
+
+
+ );
}
+
+const LoadingComponent = () => (
+
+
+
+);
+
+const ErrorComponent = ({ error }: { error: Error | null }) => (
+
+
+ Error
+ {error?.message}
+
+ Go home
+
+
+
+);
diff --git a/postcss.config.js b/postcss.config.js
index 33ad091..12a703d 100644
--- a/postcss.config.js
+++ b/postcss.config.js
@@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
-}
+};
diff --git a/tailwind.config.ts b/tailwind.config.ts
index c7ead80..2686392 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -1,4 +1,4 @@
-import type { Config } from 'tailwindcss'
+import type { Config } from 'tailwindcss';
const config: Config = {
content: [
@@ -16,5 +16,5 @@ const config: Config = {
},
},
plugins: [],
-}
-export default config
+};
+export default config;
diff --git a/types/crew.d.ts b/types/crew.d.ts
new file mode 100644
index 0000000..a3a7b9c
--- /dev/null
+++ b/types/crew.d.ts
@@ -0,0 +1,11 @@
+type CrewMember = {
+ fullName: string;
+ nationality: string;
+ age: number;
+ profession: string;
+};
+
+type CrewResponse = {
+ data: CrewMember[];
+ pagination: PaginationResponse;
+};
diff --git a/types/pagination.d.ts b/types/pagination.d.ts
new file mode 100644
index 0000000..2e11219
--- /dev/null
+++ b/types/pagination.d.ts
@@ -0,0 +1,10 @@
+type PaginationResponse = {
+ currentPage: number;
+ totalPages: number;
+ itemsPerPage: number;
+ totalItems: number;
+ lastPage: number;
+
+ previousPage: number | null;
+ nextPage: number | null;
+};
diff --git a/vitest.config.mts b/vitest.config.mts
new file mode 100644
index 0000000..f839ebf
--- /dev/null
+++ b/vitest.config.mts
@@ -0,0 +1,13 @@
+import { defineConfig } from "vitest/config";
+import react from "@vitejs/plugin-react";
+import tsconfigPaths from "vite-tsconfig-paths";
+
+// https://vitejs.dev/config/
+export default defineConfig({
+ plugins: [tsconfigPaths(), react()],
+ test: {
+ environment: "jsdom",
+ setupFiles: "./__tests__/setup.ts",
+ globals: true,
+ },
+});
Winter Camp 2024 Recruitment Task
Error
+{error?.message}
+