Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add typescript [ECO-960] #33

Merged
merged 7 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
{
"extends": ["next/babel","next/core-web-vitals"],
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"extends: next/core-web-vitals"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"@next/next/no-page-custom-font":"off",
"@next/next/no-sync-scripts":"off",
"@next/next/no-img-element":"off",
"react-hooks/exhaustive-deps":"off",
"import/no-anonymous-default-export":"off"
"react/prop-types":0,
"no-undef":"off",
"no-unused-vars": "off"
}
}
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ Read Contentstack [docs](https://www.contentstack.com/docs/)
Region support [docs](https://www.contentstack.com/docs/developers/selecting-region-in-contentstack-starter-apps)

Learn about [Next.js](https://learnnextjs.com/)









27 changes: 27 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Security

Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.

If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.

## Reporting Security Issues

**Please do not report security vulnerabilities through public GitHub issues.**

Send email to [[email protected]](mailto:[email protected]).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
import React from 'react';
import parse from 'html-react-parser';
import { Action,Image } from '../typescript/action';

export default function AboutSectionBucket({ sectionWithBuckets }) {
function bucketContent(bucket, index) {
type AdditionalParam = {
title_h2?: string;
title_h3?: string;
description?: string;
}

type Bucket = {
title_h3: string;
description: string;
icon: Image;
$: AdditionalParam;
url: string;
}

type BucketsList = {
title_h3: string;
description: string;
url: string;
call_to_action: Action;
icon: Image;
$: AdditionalParam;
}

type BucketProps = {
title_h2: string;
buckets:[BucketsList];
$: AdditionalParam;
}

export default function AboutSectionBucket({ sectionWithBuckets }: {sectionWithBuckets:BucketProps}) {
function bucketContent(bucket: Bucket, index: number) {
return (
<div className='mission-content-section' key={index}>
{bucket.icon && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@ import React from 'react';
import Link from 'next/link';
import parse from 'html-react-parser';

export default function ArchiveRelative({ blogs }) {
type AdditionalParam = {
title: string;
body: string;
}

type Blog = {
url: string;
body: string;
title: string;
$: AdditionalParam;
}

type BlogListProps = {
blogs: [Blog];
}

export default function ArchiveRelative({ blogs }: BlogListProps) {
return (
<>
{blogs?.map((blog, idx) => (
Expand Down
18 changes: 17 additions & 1 deletion components/blog-banner.js → components/blog-banner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import React from 'react';

export default function BlogBanner({ blogBanner }) {
type AdditionalParam = {
banner_title:string;
banner_description: string;
title: {};
title_h2: string;
body: string;
date: string;
}

type BannerProps = {
banner_title:string;
banner_description: string;
bg_color: string;
$: AdditionalParam;
}

export default function BlogBanner({ blogBanner }: {blogBanner : BannerProps}) {
return (
<div
className='blog-page-banner'
Expand Down
30 changes: 28 additions & 2 deletions components/blog-list.js → components/blog-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,35 @@ import React from 'react';
import moment from 'moment';
import parse from 'html-react-parser';
import Link from 'next/link';
import { Image } from "../typescript/action";

function BlogList({ bloglist }) {
let body = typeof bloglist.body === 'string' && bloglist.body.substr(0, 300);
type AdditionalParam = {
banner_title:string;
banner_description: string;
title: {};
title_h2: string;
body: string;
date: string;
}

type Author = {
title: string;
$: AdditionalParam;
}


type BloglistProps = {
body: string;
url: string;
featured_image: Image;
title: string;
date: string;
author: [Author];
$: AdditionalParam;
}

function BlogList({ bloglist }: { bloglist: BloglistProps }) {
let body: string = bloglist.body && bloglist.body.substr(0, 300);
const stringLength = body.lastIndexOf(' ');
body = `${body.substr(0, Math.min(body.length, stringLength))}...`;
return (
Expand Down
40 changes: 39 additions & 1 deletion components/blog-section.js → components/blog-section.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
import React from 'react';
import Link from 'next/link';
import parse from 'html-react-parser';
import { Image } from "../typescript/action";

type AdditionalParam = {
banner_title:string;
banner_description: string;
title: {};
title_h2: string;
body: string;
date: string;
}

type Article = {
href: string;
title: string;
$: AdditionalParam;
}

type FeaturedBlog = {
title: string;
featured_image: Image;
body: string;
url: string;
$: AdditionalParam;
}

type FeaturedBlogData = {
title_h2: string;
view_articles: Article;
featured_blogs: [FeaturedBlog]
$: AdditionalParam;
}

type FeaturedBlogProps = {
fromBlog: FeaturedBlogData;
}

export default function BlogSection(props: FeaturedBlogProps) {

const fromBlog = props.fromBlog;

export default function BlogSection({ fromBlog }) {
return (
<div className='community-section'>
<div className='community-head'>
Expand Down
19 changes: 18 additions & 1 deletion components/card-section.js → components/card-section.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import React from 'react';
import Link from 'next/link';
import { Action } from "../typescript/action";

export default function CardSection({ cards }) {
type AdditionalParam = {
title_h3: string;
description: string;
}

type Card = {
title_h3: string;
description: string;
call_to_action: Action;
$: AdditionalParam;
}

type CardProps = {
cards: [Card]
}

export default function CardSection({ cards }: CardProps) {
return (
<div className='demo-section'>
{cards?.map((card, index) => (
Expand Down
8 changes: 4 additions & 4 deletions components/devtools.js → components/devtools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Tooltip from './tool-tip';

const DynamicReactJson = dynamic(import('react-json-view'), { ssr: false });

function filterObject(inputObject) {
function filterObject(inputObject: any) {
const unWantedProps = [
'_version',
'ACL',
Expand All @@ -26,11 +26,11 @@ function filterObject(inputObject) {
return inputObject;
}

const DevTools = ({ response }) => {
const DevTools = ({ response }: any) => {
const filteredJson = filterObject(response);
const [forceUpdate, setForceUpdate] = useState(0);

function copyObject(object) {
function copyObject(object: any) {
navigator.clipboard.writeText(object);
setForceUpdate(1);
}
Expand All @@ -47,7 +47,7 @@ const DevTools = ({ response }) => {
id="staticBackdrop"
data-bs-backdrop="static"
data-bs-keyboard="false"
tabIndex="-1"
tabIndex={-1}
aria-labelledby="staticBackdropLabel"
aria-hidden="true"
role="dialog"
Expand Down
12 changes: 7 additions & 5 deletions components/footer.js → components/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import parse from 'html-react-parser';
import { onEntryChange } from '../contentstack-sdk';
import { getFooterRes } from '../helper';
import Skeleton from 'react-loading-skeleton';
import { FooterProps, Entry, Links } from "../typescript/layout";

export default function Footer({ footer, entries }) {
const [getFooter, setFooter] = useState(footer);
export default function Footer({ footer, entries }: {footer: FooterProps, entries: Entry}) {

function buildNavigation(ent, ft) {
const [getFooter, setFooter] = useState(footer);

function buildNavigation(ent: Entry, ft: FooterProps) {
let newFooter = { ...ft };
if (ent.length !== newFooter.navigation.link.length) {
ent.forEach((entry) => {
const fFound = newFooter?.navigation.link.find(
(nlink) => nlink.title === entry.title
(nlink: Links) => nlink.title === entry.title
);
if (!fFound) {
newFooter.navigation.link?.push({
Expand All @@ -29,7 +31,7 @@ export default function Footer({ footer, entries }) {

async function fetchData() {
try {
if (footer && entries != {}) {
if (footer && entries) {
const footerRes = await getFooterRes();
const newfooter = buildNavigation(entries, footerRes);
setFooter(newfooter);
Expand Down
12 changes: 7 additions & 5 deletions components/header.js → components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import Tooltip from './tool-tip';
import { onEntryChange } from '../contentstack-sdk';
import { getHeaderRes } from '../helper';
import Skeleton from 'react-loading-skeleton';
import { HeaderProps, Entry, NavLinks } from "../typescript/layout";

export default function Header({ header, entries }: {header: HeaderProps, entries: Entry}) {

export default function Header({ header, entries }) {
const router = useRouter();
const [getHeader, setHeader] = useState(header);

function buildNavigation(ent, hd) {
function buildNavigation(ent: Entry, hd: HeaderProps) {
let newHeader={...hd};
if (ent.length!== newHeader.navigation_menu.length) {
ent.forEach((entry) => {
const hFound = newHeader?.navigation_menu.find(
(navLink) => navLink.label === entry.title
(navLink: NavLinks) => navLink.label === entry.title
);
if (!hFound) {
newHeader.navigation_menu?.push({
Expand All @@ -34,7 +36,7 @@ export default function Header({ header, entries }) {

async function fetchData() {
try {
if (header && entries!=={}) {
if (header && entries) {
const headerRes = await getHeaderRes();
const newHeader = buildNavigation(entries,headerRes)
setHeader(newHeader);
Expand Down Expand Up @@ -111,7 +113,7 @@ export default function Header({ header, entries }) {
</nav>

<div className='json-preview'>
<Tooltip content='JSON Preview' direction='top'>
<Tooltip content='JSON Preview' direction='top' dynamic={false} delay={200} status={0}>
<span data-bs-toggle='modal' data-bs-target='#staticBackdrop'>
<img src='/json.svg' alt='JSON Preview icon' />
</span>
Expand Down
Loading