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

Accept payments page Implementaion #46

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
57edf62
feat: crypto page initializations
asapconet Aug 25, 2022
6b2d0d6
Merge branch 'main' of https://github.com/LazerPay-Finance/Lazerpay-d…
asapconet Aug 31, 2022
54428b0
Merge branch 'transfer-webhook' of https://github.com/asapconet/Lazer…
asapconet Aug 31, 2022
ce7381d
feat: add tables to crypto-payments
asapconet Aug 31, 2022
797734b
Merge branch 'main' of https://github.com/LazerPay-Finance/Lazerpay-d…
asapconet Aug 31, 2022
26f64d1
chore: table render method update
asapconet Aug 31, 2022
ac91577
feat: add accept-payments page x8.5
asapconet Sep 1, 2022
ed77bc5
Merge branch 'transfer-webhook' of https://github.com/asapconet/Lazer…
asapconet Sep 6, 2022
3714ed2
feat: add code snipet data
asapconet Sep 6, 2022
6983529
chore: icons casing adaptation
asapconet Sep 7, 2022
d1463f8
feat: add optional codeBlock
asapconet Sep 8, 2022
fc21f48
chore: add icon
asapconet Sep 8, 2022
80eeb0a
feat: accept-payment page completion x9
asapconet Sep 8, 2022
02b91d1
chore: code refactor
asapconet Sep 8, 2022
bc14f68
chore: dynamic code snippet rendering x5
asapconet Sep 9, 2022
72d3396
bug: breake point fix
asapconet Sep 9, 2022
96585a2
Merge branch 'accept-payments' of https://github.com/asapconet/Lazerp…
asapconet Sep 9, 2022
1e6b01a
feat: added code blocks to crypto checkout
asapconet Sep 9, 2022
91b3037
chore: screens alignments x completion of crytop-payment x9.9
asapconet Sep 9, 2022
d95c8a5
chore: minor route fixes
asapconet Sep 9, 2022
836a9e3
Merge branch 'main' of https://github.com/LazerPay-Finance/Lazerpay-d…
asapconet Sep 20, 2022
909a720
chore: typocase fix
asapconet Sep 20, 2022
fcbe351
chore: add higlightning package
asapconet Sep 27, 2022
6f5e4a6
chore: refactor accept payments to mdx
asapconet Sep 28, 2022
1613bc8
Feat: inherited new code-block configuraration
asapconet Sep 28, 2022
1173a17
bug: fix breakpoints
asapconet Sep 28, 2022
6b1b544
bug: fix breakpoints
asapconet Sep 28, 2022
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
69 changes: 47 additions & 22 deletions components/AcceptPayments/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
import classNames from "classnames";
import CodeBlock from "components/CodeBlock";
import LzButton from "components/UI/button";
import Styles from './index.module.scss';
import classNames from 'classnames'
import CodeBlock from 'components/CodeBlock'
import LzButton from 'components/UI/button'
import Styles from './index.module.scss'
import { DataProp, ItemType, RequestData } from 'components/CodeBlock/types'

export default function AcceptPayments(): JSX.Element {

return (
<section className={classNames(Styles.AcceptPayments, "flex flex-col lg:flex-row w-full lg:space-y-0 lg:space-x-6")}>
<div className="flex flex-col justify-between px-6 pt-8 pb-4 md:pt-14 rounded-t-8 lg:rounded-8 lg:w-52">
<div className="!pr-8 mb-8 lg:mb-0">
<h3 className="heading-6-s whitespace-nowrap">To get started</h3>
<p className="mt-5 paragraph-1">Authenticate all Lazerpay API calls using your secret keys.</p>
</div>
<LzButton className="w-full mt-24 paragraph-1 md:mt-0" size="md" rightIcon={'chevron'}>
Let's go
</LzButton>
</div>
<div className="lg:max-w-lg xl:max-w-xl xl:w-4/6 bg-pri-50">
<CodeBlock id="api" />
</div>
</section>
)
}
const codeObject: { type: any; item: RequestData } = {
type: 'request',
item: {
requestData: {
name: ['cURL'],
snippet: ['getStartedAcceptPaymentPostCURL'],
lang: ['curl'],
},
},
}
return (
<section
className={classNames(
Styles.AcceptPayments,
'flex flex-col lg:flex-row w-full lg:space-y-0 lg:space-x-6',
)}
>
<div className='flex flex-col justify-between px-6 pt-8 pb-4 md:pt-14 rounded-t-8 lg:rounded-8 lg:w-52'>
<div className='!pr-8 mb-8 lg:mb-0'>
<h3 className='heading-6-s whitespace-nowrap'>To get started</h3>
<p className='mt-5 paragraph-1'>
Authenticate all Lazerpay API calls using your secret keys.
</p>
</div>
<LzButton
className='w-full mt-24 paragraph-1 md:mt-0'
size='md'
rightIcon={'chevron'}
>
Let's go
</LzButton>
</div>
<div className='lg:max-w-lg xl:max-w-xl xl:w-4/6'>
<CodeBlock
responseTheme='default'
responseTitle='Response JSON'
data={codeObject}
/>
</div>
</section>
)
}
47 changes: 47 additions & 0 deletions components/CodeBlock/components/RequestHead.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import cn from 'classnames'
import LzToggle from 'components/UI/toggle'
import LzCodeSelect from 'components/UI/codeSelect'
import { RequestData, RequestType } from '../types'

const RequestHead = (props: RequestData) => {
const {
method = undefined,
requestData,
showResponse,
onChange,
toggleResponse,
} = props
const { name } = requestData as RequestType
const options = {
POST: 'bg-suc-100',
GET: 'bg-pri-500 text-neu-50',
PUT: 'bg-sec-700 text-neu-50',
}
return (
<div className='bg-neu-50'>
<div className='px-8 py-2.5 flex justify-between'>
<div className='flex items-center font-proxima'>
{method && (
<span
className={cn(
'uppercase caption-s rounded-8 px-2.5 py-1 paragraph-1-s h-fit mr-4',
options[method],
)}
>
{method}
</span>
)}
{name.length > 1 && <LzCodeSelect onChange={onChange} items={name} />}
</div>
<div className='flex items-center'>
<span className='leading-5 paragraph-1-s mr-3.5'>
{showResponse ? 'Hide Response' : 'Show Response'}
</span>
<LzToggle state={showResponse} onChange={toggleResponse} />
</div>
</div>
</div>
)
}

export default RequestHead
29 changes: 29 additions & 0 deletions components/CodeBlock/components/ResponseHead.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ItemType } from '../types'
import LzCodeSelect from 'components/UI/codeSelect'

export type ResponseProp = {
title: string
item: ItemType
onChange: (i: number) => void
}

const ResponseHead = (props: ResponseProp) => {
const { title, item, onChange } = props
const { name } = item as ItemType
return (
<div className='bg-neu-50'>
<div className='px-8 py-2.5 flex justify-between border-b border-neu-200'>
<div className='flex items-center'>
<h4 className='paragraph-1-s text-neu-600'>{title || 'Response'}</h4>
</div>
<div className='flex items-center'>
{item.name.length > 1 ? (
<LzCodeSelect onChange={onChange} items={name} />
) : null}
</div>
</div>
</div>
)
}

export default ResponseHead
48 changes: 48 additions & 0 deletions components/CodeBlock/components/TabHead.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useState, MouseEvent } from 'react'
import cn from 'classnames'

export type TabProps = {
items: string[]
onChange: (i: number) => void
}

const TabHead = (props: TabProps) => {
const { items, onChange } = props
const [active, setActive] = useState<number>(0)

const tabItemClassName = (i: number): string => {
return cn('py-3.5 px-2.5 text-neu-400 paragraph-1-s relative mr-4', {
'text-pri-600 paragraph-1-s': i === active,
})
}

const onTabClicked = (e: MouseEvent<HTMLButtonElement>): void => {
e.preventDefault()
const { dataset } = e.target as HTMLButtonElement
setActive(Number(dataset.value))
onChange(Number(dataset.value))
}
return (
<div className='bg-white'>
<ul className='flex items-center px-8 paragraph-1-s'>
{items.map((title: string, i: number) => (
<li key={title} className={tabItemClassName(i)}>
<button
type='button'
aria-label={title}
data-value={i}
onClick={onTabClicked}
>
{title}
</button>
{i === active && (
<div className='absolute bottom-0 left-0 w-full h-1 bg-pri-500 rounded-t-2xl'></div>
)}
</li>
))}
</ul>
</div>
)
}

export default TabHead
3 changes: 3 additions & 0 deletions components/CodeBlock/components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as RequestHead } from './RequestHead'
export { default as ResponseHead } from './ResponseHead'
export { default as TabHead } from './TabHead'
49 changes: 49 additions & 0 deletions components/CodeBlock/configurePrism.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const initializePrism = (Prism) => {
Prism.languages.json = {
'property': {
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
lookbehind: true,
greedy: true
},
'string': {
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
lookbehind: true,
greedy: true
},
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true
},
'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
'punctuation': /[{}[\],]/,
'operator': /:/,
'boolean': /\b(?:false|true)\b/,
'null': {
pattern: /\bnull\b/,
alias: 'keyword'
}
};

Prism.languages.curl = {
'curl': /\bcurl\b/,
'url': /https?:[a-zA-Z0-9:.?=\/\-_{}]*/,
'parameter': {
pattern: /[A-Za-z0-9\[\]-_]+ *(?=[=])/,
},
'value': [{
pattern: /([=])([A-Za-z0-9-_.]*)/,
lookbehind: true,
}, {
pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
}, {
pattern: /(\-u )([A-Za-z0-9-_.{}]*)/,
lookbehind: true,
}],
'punctuation': /[{}['’\],]/,
'method': /(?:POST|GET|PATCH|PUT)/g,
'option': / *--[a-zA-Z-]*\b/,
};

Prism.languages.webmanifest = Prism.languages.json;
}
export { initializePrism };
42 changes: 42 additions & 0 deletions components/CodeBlock/hooks/useStateSnippets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { snippets } from 'data/snippets';
import { useState, useEffect } from 'react';

import { ItemType, RequestData, RequestType } from '../types';

export type StateSnippetProps = {
type: any;
item: any;
}

export type StateSnippetTypes = {
language: string;
codeSnippet: string;
updateSnippet: any;
}

const useStateSnippet = ({ type, item }: StateSnippetProps): StateSnippetTypes => {
const [codeSnippet, setCodeSnippet] = useState<string>("");
const [language, setLanguage] = useState<string>("jsx");

const updateSnippet = (snippet, lang) => {
setCodeSnippet(snippet);
setLanguage(lang);
}

useEffect(() => {
if (type === 'tab') {
updateSnippet(snippets[(item as ItemType).snippet[0]], (item as ItemType).lang[0]);
}
if (type === 'request') {
const { requestData } = item as RequestData;
updateSnippet(snippets[(requestData as RequestType).snippet[0]], (requestData as RequestType).lang[0])
}
if (type === 'response') {
updateSnippet(snippets[(item as ItemType).snippet[0]], 'json');
}
}, []);

return { language, codeSnippet, updateSnippet };
}

export default useStateSnippet;
22 changes: 19 additions & 3 deletions components/CodeBlock/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,31 @@
position: absolute;
top: -100px;
}

/* Track */
::-webkit-scrollbar-track {
background-color: #FFF;
position: absolute;
}

/* Handle */
::-webkit-scrollbar-thumb {
background: #C2C2C2;
background: #C2C2C2;
border-radius: 50px;
position: absolute;
}
}

.select {
box-shadow: 0px 0px 1px rgba(12, 26, 75, 0.24), 0px 3px 8px -1px rgba(50, 50, 71, 0.05);
visibility: hidden;
top: 1.9rem;
opacity: 0;
transition: all .1s ease-out;
}

.selectActive {
visibility: visible;
top: 1.3rem;
opacity: 1;
}
Loading