Skip to content

Commit

Permalink
fix: remove redirecting to not-permission page (#142)
Browse files Browse the repository at this point in the history
feat: remove permission
  • Loading branch information
chiol authored Jan 24, 2024
1 parent b304947 commit a4b16c4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 130 deletions.
4 changes: 2 additions & 2 deletions apps/web/src/pages/auth/oauth-callback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ const OAuthCallbackPage: NextPage<IProps> = () => {

return (
<div className="flex h-screen w-screen items-center justify-center">
<h1 className="font-32-bold animate-bounce">
<p className="font-32-bold animate-bounce">
{status === 'loading'
? 'Loading...'
: status === 'error'
? 'Error!!!'
: ''}
</h1>
</p>
</div>
);
};
Expand Down
20 changes: 0 additions & 20 deletions apps/web/src/pages/main/project/[projectId]/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
import { useLayoutEffect, useMemo, useRef, useState } from 'react';
import type { GetServerSideProps } from 'next';
import dayjs from 'dayjs';
import { getIronSession } from 'iron-session';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'react-i18next';

import { Icon } from '@ufb/ui';

import { DateRangePicker, MainTemplate } from '@/components';
import { DEFAULT_LOCALE } from '@/constants/i18n';
import { ironOption } from '@/constants/iron-option';
import { Path } from '@/constants/path';
import {
CreateFeedbackPerIssueCard,
Expand All @@ -44,7 +42,6 @@ import {
YesterdayIssueCard,
} from '@/containers/dashboard';
import FeedbackLineChart from '@/containers/dashboard/FeedbackLineChart';
import { env } from '@/env.mjs';
import useQueryParamsState from '@/hooks/useQueryParamsState';
import type { NextPageWithLayout } from '@/pages/_app';
import type { DateRangeType } from '@/types/date-range.type';
Expand Down Expand Up @@ -250,26 +247,9 @@ const CardSlider: React.FC<ICardSliderProps> = ({ children }) => {
export const getServerSideProps: GetServerSideProps = async ({
query,
locale,
req,
res,
}) => {
const session = await getIronSession(req, res, ironOption);
const projectId = parseInt(query.projectId as string);

const response = await fetch(
`${env.API_BASE_URL}/api/projects/${projectId}`,
{ headers: { Authorization: 'Bearer ' + session.jwt?.accessToken } },
);

if (response.status === 401) {
return {
redirect: {
destination: `/main/${projectId}/not-permission`,
permanent: true,
},
};
}

return {
props: {
...(await serverSideTranslations(locale ?? DEFAULT_LOCALE)),
Expand Down
43 changes: 11 additions & 32 deletions apps/web/src/pages/main/project/[projectId]/feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@
* under the License.
*/
import type { GetServerSideProps } from 'next';
import { getIronSession } from 'iron-session';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'react-i18next';

import { MainTemplate } from '@/components';
import { DEFAULT_LOCALE } from '@/constants/i18n';
import { ironOption } from '@/constants/iron-option';
import { FeedbackTable } from '@/containers';
import { CreateChannelButton } from '@/containers/buttons';
import { env } from '@/env.mjs';
import { useOAIQuery } from '@/hooks';
import type { NextPageWithLayout } from '@/pages/_app';

interface IProps {
projectId: number;
channelId?: number | null;
noChannel?: boolean;
}

const FeedbackManagementPage: NextPageWithLayout<IProps> = (props) => {
const { projectId, channelId, noChannel } = props;
const { projectId, channelId } = props;
const { data, status } = useOAIQuery({
path: '/api/projects/{projectId}/channels',
variables: { projectId },
});

const { t } = useTranslation();

Expand All @@ -44,7 +45,11 @@ const FeedbackManagementPage: NextPageWithLayout<IProps> = (props) => {
return (
<>
<h1 className="font-20-bold mb-3">{t('main.feedback.title')}</h1>
{noChannel ? (
{status === 'pending' ? (
<p className="font-32-bold animate-bounce">Loading...</p>
) : status === 'error' ? (
<p className="font-32-bold">Not Permission</p>
) : data.meta.totalItems === 0 ? (
<div className="flex flex-1 items-center justify-center">
<CreateChannelButton projectId={projectId} type="blue" />
</div>
Expand All @@ -62,35 +67,9 @@ FeedbackManagementPage.getLayout = function getLayout(page) {
export const getServerSideProps: GetServerSideProps = async ({
query,
locale,
req,
res,
}) => {
const session = await getIronSession(req, res, ironOption);
const projectId = parseInt(query.projectId as string);

const response = await fetch(
`${env.API_BASE_URL}/api/projects/${projectId}/channels`,
{ headers: { Authorization: 'Bearer ' + session.jwt?.accessToken } },
);
if (response.status === 401) {
return {
redirect: {
destination: `/main/${projectId}/not-permission`,
permanent: true,
},
};
}
const data = await response.json();
if (data.meta.totalItems === 0) {
return {
props: {
...(await serverSideTranslations(locale ?? DEFAULT_LOCALE)),
projectId,
noChannel: true,
},
};
}

return {
props: {
...(await serverSideTranslations(locale ?? DEFAULT_LOCALE)),
Expand Down
59 changes: 12 additions & 47 deletions apps/web/src/pages/main/project/[projectId]/issue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,35 @@
* under the License.
*/
import type { GetServerSideProps } from 'next';
import { getIronSession } from 'iron-session';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'react-i18next';

import { MainTemplate } from '@/components';
import { DEFAULT_LOCALE } from '@/constants/i18n';
import { ironOption } from '@/constants/iron-option';
import { CreateChannelButton } from '@/containers/buttons';
import { IssueTable } from '@/containers/tables';
import { env } from '@/env.mjs';
import { useOAIQuery } from '@/hooks';
import type { NextPageWithLayout } from '../../../_app';

interface IProps {
projectId: number;
noChannel?: boolean;
}
const IssueMangementPage: NextPageWithLayout<IProps> = (props) => {
const { projectId, noChannel } = props;
const { projectId } = props;
const { t } = useTranslation();
const { data, status } = useOAIQuery({
path: '/api/projects/{projectId}/channels',
variables: { projectId },
});

return (
<>
<h1 className="font-20-bold mb-3">{t('main.issue.title')}</h1>
{noChannel ? (
{status === 'pending' ? (
<p className="font-32-bold animate-bounce">Loading...</p>
) : status === 'error' ? (
<p className="font-32-bold">Not Permission</p>
) : data.meta.totalItems === 0 ? (
<div className="flex flex-1 items-center justify-center">
<CreateChannelButton projectId={projectId} type="blue" />
</div>
Expand All @@ -52,52 +58,11 @@ IssueMangementPage.getLayout = function getLayout(page) {
};

export const getServerSideProps: GetServerSideProps<IProps> = async ({
req,
res,
locale,
query,
}) => {
const session = await getIronSession(req, res, ironOption);

const projectId = parseInt(query.projectId as string);

const response1 = await fetch(
`${env.API_BASE_URL}/api/projects/${projectId}`,
{ headers: { Authorization: 'Bearer ' + session.jwt?.accessToken } },
);

if (response1.status === 401) {
return {
redirect: {
destination: `/main/${projectId}/not-permission`,
permanent: true,
},
};
}

const response2 = await fetch(
`${env.API_BASE_URL}/api/projects/${projectId}/channels`,
{ headers: { Authorization: 'Bearer ' + session.jwt?.accessToken } },
);
if (response2.status === 401) {
return {
redirect: {
destination: `/main/${projectId}/not-permission`,
permanent: true,
},
};
}
const data = await response2.json();
if (data.meta.totalItems === 0) {
return {
props: {
...(await serverSideTranslations(locale ?? DEFAULT_LOCALE)),
projectId,
noChannel: true,
},
};
}

return {
props: {
...(await serverSideTranslations(locale ?? DEFAULT_LOCALE)),
Expand Down
30 changes: 1 addition & 29 deletions apps/web/src/pages/main/project/[projectId]/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import { useEffect, useMemo, useState } from 'react';
import type { GetServerSideProps } from 'next';
import { useRouter } from 'next/router';
import { getIronSession } from 'iron-session';
import { useTranslation } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';

Expand All @@ -25,7 +24,6 @@ import { Icon } from '@ufb/ui';
import { MainTemplate } from '@/components';
import { SettingMenuBox } from '@/components/layouts/setting-menu';
import { DEFAULT_LOCALE } from '@/constants/i18n';
import { ironOption } from '@/constants/iron-option';
import { Path } from '@/constants/path';
import {
APIKeySetting,
Expand All @@ -44,7 +42,6 @@ import {
TicketSetting,
UserSetting,
} from '@/containers/setting-menu';
import { env } from '@/env.mjs';
import type { SettingMenuType } from '@/types/setting-menu.type';
import type { NextPageWithLayout } from '../../../_app';

Expand Down Expand Up @@ -184,36 +181,11 @@ SettingPage.getLayout = function getLayout(page) {
};

export const getServerSideProps: GetServerSideProps<IProps> = async ({
req,
res,
locale,
query,
}) => {
const session = await getIronSession(req, res, ironOption);

const projectId = parseInt(query.projectId as string);
try {
const data = await (
await fetch(`${env.API_BASE_URL}/api/projects/${projectId}`, {
headers: { Authorization: 'Bearer ' + session.jwt?.accessToken },
})
).json();
if (data?.statusCode === 401) {
return {
redirect: {
destination: `/main/${projectId}/not-permission`,
permanent: true,
},
};
}
} catch (error) {
return {
redirect: {
destination: `/main/${projectId}/not-permission`,
permanent: true,
},
};
}

return {
props: {
...(await serverSideTranslations(locale ?? DEFAULT_LOCALE)),
Expand Down

0 comments on commit a4b16c4

Please sign in to comment.