Skip to content

Commit

Permalink
Merge pull request #45 from the-deep/feature/about
Browse files Browse the repository at this point in the history
Add about page
  • Loading branch information
AdityaKhatri authored Sep 12, 2023
2 parents 722941e + 24c805c commit 9d6eb4d
Show file tree
Hide file tree
Showing 11 changed files with 753 additions and 28 deletions.
13 changes: 13 additions & 0 deletions src/App/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ const register = myWrapRoute({
},
});

const about = myWrapRoute({
path: 'about',
component: {
render: () => import('#views/About'),
props: {},
},
context: {
title: 'About',
visibility: 'is-authenticated',
},
});

const resetPassword = myWrapRoute({
path: 'reset-password',
component: {
Expand Down Expand Up @@ -173,6 +185,7 @@ export const wrappedRoutes = {
home,
login,
register,
about,
resetPassword,
forgotPassword,
resetPasswordRedirect,
Expand Down
7 changes: 5 additions & 2 deletions src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ function Navbar(props: Props) {
</NavLink>
<NavLink
// FIXME: Fix the routing
className={styles.navItem}
to="/"
className={_cs(
styles.navItem,
location.pathname === '/about' && styles.active,
)}
to="/about"
>
About
</NavLink>
Expand Down
3 changes: 2 additions & 1 deletion src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

--dui-color-primary: #5A3070;
--dui-color-secondary: #EFEDF7;
--dui-color-outline: #CAA9DB;
--dui-color-background-hover-primary-button: #6E4780;

--dui-color-background: #FFF;
--dui-color-foreground: #F9F9F9;

--dui-color-foreground-scrollbar: #DAD4F1;
--dui-color-foreground-scrollbar: #e0e0e0;

--text-color: #414141;
--text-color-dark: #00033F;
Expand Down
10 changes: 10 additions & 0 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export type NonLeafTocItem = {
nodes: TocItem[];
}

export interface Node {
category: {
key: string;
label: string;
}[];
type?: string;
id: string;
isHidden: boolean;
}

export type TocItem = LeafTocItem | NonLeafTocItem;

export function getChildren(item: TocItem): string[] {
Expand Down
6 changes: 6 additions & 0 deletions src/views/About/QuestionsPreview/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.question-list {
display: flex;
flex-direction: column;
padding: var(--dui-spacing-medium);
gap: var(--dui-spacing-large);
}
215 changes: 215 additions & 0 deletions src/views/About/QuestionsPreview/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import { useMemo, useCallback } from 'react';
import { gql, useQuery } from '@apollo/client';
import {
isDefined,
} from '@togglecorp/fujs';
import {
ListView,
} from '@the-deep/deep-ui';

import {
QuestionsFromBankQuery,
QuestionsFromBankQueryVariables,
} from '#generated/types';
import TextQuestionPreview from '#components/questionPreviews/TextQuestionPreview';
import IntegerQuestionPreview from '#components/questionPreviews/IntegerQuestionPreview';
import RankQuestionPreview from '#components/questionPreviews/RankQuestionPreview';
import DateQuestionPreview from '#components/questionPreviews/DateQuestionPreview';
import TimeQuestionPreview from '#components/questionPreviews/TimeQuestionPreview';
import NoteQuestionPreview from '#components/questionPreviews/NoteQuestionPreview';
import ImageQuestionPreview from '#components/questionPreviews/ImageQuestionPreview';
import FileQuestionPreview from '#components/questionPreviews/FileQuestionPreview';
import SelectOneQuestionPreview from '#components/questionPreviews/SelectOneQuestionPreview';
import SelectMultipleQuestionPreview from '#components/questionPreviews/SelectMultipleQuestionPreview';
import {
type ProjectScope,
} from '#utils/common';

import styles from './index.module.css';

const QUESTIONS_FROM_BANK = gql`
query QuestionsFromBank (
$leafGroupId: ID!,
$questionnaireId: ID!,
$projectId: ID!,
) {
private {
projectScope(pk: $projectId) {
questions(filters: {
leafGroup: {
pk: $leafGroupId
}
questionnaire: { pk: $questionnaireId }
}) {
items {
id
label
name
type
hint
leafGroupId
questionnaireId
choiceCollection {
id
name
label
questionnaireId
}
}
}
}
}
}
`;

type Question = NonNullable<NonNullable<ProjectScope<QuestionsFromBankQuery>['questions']>['items']>[number];

const questionKeySelector = (question: Question) => question.id;

interface QuestionProps {
projectId: string;
question: Question;
}

function QuestionRenderer(props: QuestionProps) {
const {
projectId,
question,
} = props;

return (
<div className={styles.preview}>
{(question.type === 'TEXT') && (
<TextQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
/>
)}
{(question.type === 'INTEGER') && (
<IntegerQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
/>
)}
{(question.type === 'RANK') && isDefined(projectId) && (
<RankQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
projectId={projectId}
choiceCollectionId={question.choiceCollection?.id}
/>
)}
{(question.type === 'DATE') && (
<DateQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
/>
)}
{(question.type === 'TIME') && (
<TimeQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
/>
)}
{(question.type === 'NOTE') && (
<NoteQuestionPreview
className={styles.questionItem}
label={question.label}
/>
)}
{(question.type === 'FILE') && (
<FileQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
/>
)}
{(question.type === 'IMAGE') && (
<ImageQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
/>
)}
{(question.type === 'SELECT_ONE') && isDefined(projectId) && (
<SelectOneQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
projectId={projectId}
choiceCollectionId={question.choiceCollection?.id}
/>
)}
{(question.type === 'SELECT_MULTIPLE') && isDefined(projectId) && (
<SelectMultipleQuestionPreview
className={styles.questionItem}
label={question.label}
hint={question.hint}
projectId={projectId}
choiceCollectionId={question.choiceCollection?.id}
/>
)}
</div>
);
}

interface Props {
id: string;
questionnaireId: string;
projectId: string;
}

function QuestionsPreview(props: Props) {
const {
id,
questionnaireId,
projectId,
} = props;

const variables = useMemo(() => ({
leafGroupId: id,
questionnaireId,
projectId,
}), [
id,
questionnaireId,
projectId,
]);

const {
data: questionsResponse,
loading: questionsPending,
} = useQuery<QuestionsFromBankQuery, QuestionsFromBankQueryVariables>(
QUESTIONS_FROM_BANK,
{
variables,
},
);

const questions = questionsResponse?.private?.projectScope?.questions?.items;
const questionRendererParams = useCallback((_: string, datum: Question) => ({
projectId,
question: datum,
}), [projectId]);

return (
<ListView
className={styles.questionList}
data={questions}
keySelector={questionKeySelector}
renderer={QuestionRenderer}
rendererParams={questionRendererParams}
borderBetweenItem
errored={false}
filtered={false}
pending={questionsPending}
/>
);
}

export default QuestionsPreview;
Loading

0 comments on commit 9d6eb4d

Please sign in to comment.