Skip to content

Commit

Permalink
Merge branch 'main' into 10-feature-Home-API
Browse files Browse the repository at this point in the history
  • Loading branch information
iOdiO89 committed Jul 1, 2024
2 parents f0c4826 + 88bb7ff commit 5ddbcfb
Show file tree
Hide file tree
Showing 42 changed files with 630 additions and 140 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Sample workflow for building and deploying a Next.js site to GitHub Pages
#
# To get started with Next.js see: https://nextjs.org/docs/getting-started
#
name: Test Next Build

on:
pull_request:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest

env:
NEXT_PUBLIC_API_URL: ${{secrets.NEXT_PUBLIC_API_URL}}

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Setup Pages
uses: actions/configure-pages@v5
with:
# Automatically inject basePath in your Next.js configuration file and disable
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
#
# You may remove this line if you want to manage the configuration yourself.
static_site_generator: next
- name: Restore cache
uses: actions/cache@v4
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Check environment variable
run: echo NEXT_PUBLIC_API_URL
- name: Create .env file
run: |
echo NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} >> .env
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
- name: Export with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next export
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./out
9 changes: 4 additions & 5 deletions .github/workflows/nextjs.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
push:
branches: ["deploy"]
pull_request:
branches: ["deploy", "main"]
branches: ["deploy"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -31,9 +31,9 @@ jobs:
build:
runs-on: ubuntu-latest

env:
NEXT_PUBLIC_API_URL: ${{secrets.NEXT_PUBLIC_API_URL}}
env:
NEXT_PUBLIC_API_URL: ${{secrets.NEXT_PUBLIC_API_URL}}

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -93,7 +93,6 @@ jobs:
with:
path: ./out


# Deployment job
deploy:
environment:
Expand Down
25 changes: 25 additions & 0 deletions apis/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { CalendarDate } from "./calendar";
import client, { ResponseBody } from "./client";

export interface Program {
name: string;
dueDate: CalendarDate;
openDate: CalendarDate;
location: string;
category: string;
host: string;
schedule: string;
description: string;
}

async function postAttendanceCode(challengeIdx: number): Promise<ResponseBody> {
const { data } = await client.post(`/challenges/attendance/${challengeIdx}`);
return data;
}

async function postProgram(body: Program): Promise<ResponseBody> {
const { data } = await client.post(`/programs`, body);
return data;
}

export { postAttendanceCode, postProgram };
7 changes: 4 additions & 3 deletions apis/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ interface GetMonthCalendarResponse extends ResponseBody {
export interface MonthCalendarProps {
programIdx: number;
name: string;
category: string | null;
location: string | null;
openDate: {
year: number;
month: number;
Expand All @@ -19,7 +21,7 @@ export interface MonthCalendarProps {
};
}

type CalendarDate = {
export type CalendarDate = {
year: number;
month: number;
day: number;
Expand All @@ -38,7 +40,7 @@ interface GetProgramDetailBody {

// 챌린지 월별 조회
export const getMonthCalendar = async (): Promise<GetMonthCalendarResponse> => {
const response = await client.get("/programs");
const response = await client.get("/programs/list");
// console.log("calenderData", response.data.result);
return response.data.result;
};
Expand All @@ -48,6 +50,5 @@ export const getProgramDetail = async (
): Promise<GetProgramDetailBody> => {
// const response = await client.get(`/programs/${programIdx}`);
const response = await client.get(`/programs/2`);
// console.log("calenderDetail", response.data.result);
return response.data.result;
};
18 changes: 18 additions & 0 deletions apis/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ async function getMyChallengeList(): Promise<GetMyChallengeListResponse> {
return data;
}

type AttendanceDate = {
year: number;
month: number;
day: number;
};

export interface GetChallengeDetailBody {
attendanceDate: AttendanceDate;
}

async function getChallengDetail(): Promise<GetChallengeDetailBody> {
const response = await client.get(
`/challenges/attendance/2?year=2024&month=6`,
);
return response.data.result;
}

async function getChallengeAds(): Promise<GetChallengeAdsResponse> {
const { data } = await client.get(`/challenges/ads`);
return data;
Expand Down Expand Up @@ -67,4 +84,5 @@ export {
getChallengeSearch,
postNewChallenge,
postAttendance,
getChallengDetail,
};
12 changes: 12 additions & 0 deletions apis/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ const getTokenFromLocalStorage = () => {
return accessToken;
};

export const setIsAdminAtLocalStorage = (is_admin: string) => {
localStorage.setItem("is_admin", is_admin);
};

const getIsAdminFromLocalStorage = () => {
const isAdmin = localStorage.getItem("is_admin");
if (!isAdmin) {
return null;
}
return isAdmin;
};

const client = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL,
withCredentials: true,
Expand Down
36 changes: 36 additions & 0 deletions apis/hooks/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { Program, postAttendanceCode, postProgram } from "../admin";
import { useRouter } from "next/router";

function usePostAttendanceCode(challengeIdx: number) {
const { mutate } = useMutation({
mutationKey: ["postAttendanceCode", challengeIdx],
mutationFn: () => postAttendanceCode(challengeIdx),
onSuccess: (data) => window.alert(`인증번호: ${data}`),
onError: () => window.alert("에러 발생. 앱 관리자에게 문의해주세요."),
});

return { mutate };
}

function usePostProgram() {
const router = useRouter();
const queryclient = useQueryClient();

const { mutate } = useMutation({
mutationKey: ["postProgram"],
mutationFn: (body: Program) => postProgram(body),
onSuccess: () => {
queryclient.invalidateQueries({
queryKey: ["getMyChallengeList"],
});
window.alert("프로그램이 성공적으로 등록되었습니다.");
router.push("/");
},
onError: () => router.push("/404"),
});

return { mutate };
}

export { usePostAttendanceCode, usePostProgram };
10 changes: 10 additions & 0 deletions apis/hooks/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getMyChallengeList,
postAttendance,
postNewChallenge,
getChallengDetail,
} from "../challenge";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";

Expand All @@ -17,6 +18,14 @@ function useGetMyChallengeList() {
return { data };
}

function useGetChallengeDetail() {
const { data } = useQuery({
queryKey: ["getChallengeDetail"],
queryFn: getChallengDetail,
});
return { data };
}

function useGetChallengeAds() {
const { data } = useQuery({
queryKey: ["getChallengeAds"],
Expand Down Expand Up @@ -72,4 +81,5 @@ export {
useGetChallengeSearch,
usePostNewChallenge,
usePostAttendance,
useGetChallengeDetail,
};
2 changes: 1 addition & 1 deletion components/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface DividerProps {
export default function Divider({ height }: DividerProps) {
return (
<div
className="border-t border-gray-100 bg-gray-100 w-full"
className="border-t border-grey-100 bg-grey-100 w-full"
style={{ height: `${height}px` }}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export default function TextInput({
<div
className={`w-full border ${
isError ? "border-red-500" : "border-transparent"
} bg-gray-100 rounded-lg p-2`}
} bg-grey-100 rounded-lg p-2`}
>
<input
type={type}
className="w-full outline-none border-none bg-gray-100 h4"
className="w-full outline-none border-none bg-grey-100 h4 placeholder:text-grey-400"
value={value}
onChange={(event) => onChangeText(event)}
placeholder={placeholder}
Expand Down
Loading

0 comments on commit 5ddbcfb

Please sign in to comment.