Skip to content

Commit

Permalink
Improved sidebar form settings
Browse files Browse the repository at this point in the history
Added google analytics script
Minor fixes related to the Dockerfile and UI
  • Loading branch information
coredumped7893 committed Feb 2, 2024
1 parent b19221a commit 58eea11
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 87 deletions.
64 changes: 64 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
image: docker:latest
services:
- docker:dind

stages:
- build_docker
- deploy

variables:
DOCKER_HOST: "tcp://docker:2375"
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
RESTART_ONLY:
value: "false"
description: "Change to 'true' if you want to restart application only."

.update_env_only_exceptions:
only:
variables:
- $RESTART_ONLY != 'true'

.docker-build:
image: bentolor/docker-dind-awscli
stage: build_docker
tags:
- docker
environment:
name: ${CI_COMMIT_REF_NAME}
script:
- cp "$DOCKER_ENV_VARIABLES" ./.env.local
- docker build -t $DOCKER_REGISTRY:$DOCKER_TAG .
- aws ecr get-login-password | docker login --username AWS --password-stdin $DOCKER_REGISTRY
- docker push $DOCKER_REGISTRY:$DOCKER_TAG

.deploy:
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
stage: deploy
tags:
- docker
environment:
name: ${CI_COMMIT_REF_NAME}
script:
- echo "sciagam i porownuje zmienne srodowiskowe"
- cp "$DOCKER_ENV_VARIABLES" ./local_$ECS_SERVICE.env
- aws s3 cp s3://$AWS_DOCKER_ENV_VARIABLES_BUCKET/$ECS_SERVICE/.env aws_$ECS_SERVICE.env || touch aws_$ECS_SERVICE.env
- cmp -s local_$ECS_SERVICE.env aws_$ECS_SERVICE.env || aws s3 cp local_$ECS_SERVICE.env s3://$AWS_DOCKER_ENV_VARIABLES_BUCKET/$ECS_SERVICE/.env
- aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment

docker-build:
extends:
- .update_env_only_exceptions
- .docker-build
only:
refs:
- develop
- master

deploy:
extends:
- .deploy
only:
refs:
- develop
- master
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM node:20-alpine AS base
WORKDIR /app
COPY . .
RUN npm i
RUN npm install -g pnpm
RUN pnpm i

EXPOSE 3000

Expand Down
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const nextConfig = {
},
{
test: /\.svg$/i,
issuer: /.[jt]sx?$/,
resourceQuery: { not: /url/ }, // exclude if *.svg?url
use: ['@svgr/webpack']
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smart-beaver-wizard",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"husky": {
"hooks": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"debounce": "^2.0.0",
"highlight.js": "^11.9.0",
"husky": "^8.0.3",
"ink-generator": "^0.3.3",
"ink-generator": "^0.3.5",
"next": "14.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/assets/icons/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions src/components/analitics/GoogleTagManager.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use client';
import Script from 'next/script';
import { env } from '@/env/env.mjs';

const GoogleTagManager: React.FC = () => {
if (env.NEXT_PUBLIC_ENVIRONMENT !== 'production') {
return null;
}

return (
<>
<noscript>
<iframe
src={`https://www.googletagmanager.com/ns.html?id=${env.NEXT_PUBLIC_GA_ID}`}
height="0"
width="0"
style={{ display: 'none', visibility: 'hidden' }}
/>
</noscript>
<Script
id="gtm-script"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${env.NEXT_PUBLIC_GA_ID}');
`
}}
/>
</>
);
};

export default GoogleTagManager;
9 changes: 6 additions & 3 deletions src/components/data-entry/CheckboxChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { dictionary } from '@/libs/en';
interface CheckboxChipProps {
label: string;
name: string;
disabled?: boolean;
}

export function CheckboxChip({ label, name }: CheckboxChipProps) {
export function CheckboxChip({ label, name, disabled }: CheckboxChipProps) {
const { register } = useFormContext();

const {
Expand All @@ -18,10 +19,12 @@ export function CheckboxChip({ label, name }: CheckboxChipProps) {

return (
<div>
<input type="checkbox" id={id} {...register(name)} className="peer hidden" />
<input type="checkbox" id={id} {...register(name)} className="peer hidden" disabled={disabled} />
<label
htmlFor={id}
className="bg-transparent inline-flex cursor-pointer items-center justify-between rounded-full border border-teal-500 p-1.5 text-teal-500 hover:bg-teal-900 hover:text-teal-500 peer-checked:border-teal-500 peer-checked:bg-teal-500 peer-checked:text-teal-950 peer-checked:hover:bg-teal-600 peer-checked:hover:text-teal-950"
className={`bg-transparent inline-flex cursor-pointer items-center justify-between rounded-full border border-teal-500 p-1.5 text-teal-500 hover:bg-teal-900 hover:text-teal-500 peer-checked:border-teal-500 peer-checked:bg-teal-500 peer-checked:text-teal-950 peer-checked:hover:bg-teal-600 peer-checked:hover:text-teal-950 ${
disabled && 'opacity-50'
}`}
>
<div className="block">
<div className="text-sm font-semibold">{label}</div>
Expand Down
53 changes: 53 additions & 0 deletions src/components/data-entry/Switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Switch as HeadlessSwitch } from '@headlessui/react';
import { useController } from 'react-hook-form';
import { ErrorMessageForm } from '@/components/data-entry/ErrorMessageForm';
import { dictionary } from '@/libs/en';
import { cn } from '@/utils/helpers/cn';

interface SwitchProps {
label?: string;
name: string;
disabled?: boolean;
}

export default function Switch({ name, label, disabled }: SwitchProps) {
const {
fieldState: { error },
field: { onChange, ...restField }
} = useController({ name });

return (
<>
<HeadlessSwitch.Group as="div" className="items-left flex gap-8 py-6">
<HeadlessSwitch
{...restField}
onChange={(e) => {
onChange(e);
}}
disabled={disabled}
className={cn(
'border-transparent relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-teal-700 focus:ring-offset-2 ',
restField.value ? 'bg-teal-600' : 'bg-transparent',
disabled && 'opacity-50'
)}
>
<span
aria-hidden="true"
className={cn(
'pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out',
restField.value ? 'translate-x-5' : 'translate-x-0'
)}
/>
</HeadlessSwitch>
{label && (
<HeadlessSwitch.Label as="div">
<div className="font-medium text-teal-600">{label}</div>
</HeadlessSwitch.Label>
)}
</HeadlessSwitch.Group>
{error && (
<ErrorMessageForm errorMessage={error.message ? error.message : dictionary.validation.defaultErrorMsg} />
)}
</>
);
}
8 changes: 2 additions & 6 deletions src/components/homepage/code-editor/CodeEditorTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function CodeEditorTabs({ activeTab, handleActiveTab, wasmFileDat
</select>
</div>
<div className="hidden xl:block">
<nav className="divide-gray-200 isolate flex rounded-lg" aria-label="Tabs">
<nav className="isolate flex rounded-lg" aria-label="Tabs">
{wasmFileData.map((tab, tabIndex) => (
<button
key={tabIndex}
Expand All @@ -66,14 +66,10 @@ export default function CodeEditorTabs({ activeTab, handleActiveTab, wasmFileDat
tabIndex > 0 ? 'border-l' : '',
tabIndex === 0 ? 'rounded-tl-lg' : '',
tabIndex === wasmFileData.length - 1 ? 'rounded-tr-lg' : '',
'hover:bg-gray-50 group relative min-w-0 flex-1 cursor-pointer overflow-hidden border-b px-4 py-4 text-center text-sm font-medium transition duration-300 focus:z-10'
'group relative min-w-0 flex-1 cursor-pointer overflow-hidden border-b px-4 py-4 text-center text-sm font-medium transition duration-300 focus:z-10'
)}
>
<span>{tab.name}</span>
<span
aria-hidden="true"
className={cn(tab.name ? 'bg-indigo-500' : 'bg-transparent', 'absolute inset-x-0 bottom-0 h-0.5')}
/>
</button>
))}
</nav>
Expand Down
41 changes: 26 additions & 15 deletions src/components/homepage/sidebar-form/SidebarForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { zodResolver } from '@hookform/resolvers/zod';
import debounce from 'debounce';
import { FormProvider, useForm } from 'react-hook-form';
import { z } from 'zod';
import Switch from '@/components/data-entry/Switch';
import AccessControl from '@/components/homepage/sidebar-form/form-sections/AccessControl';
import Features from '@/components/homepage/sidebar-form/form-sections/Features';
import License from '@/components/homepage/sidebar-form/form-sections/License';
import Metadata from '@/components/homepage/sidebar-form/form-sections/Metadata';
import NotAvailable from '@/components/homepage/sidebar-form/form-sections/NotAvailable';
import Standard from '@/components/homepage/sidebar-form/form-sections/Standard';
import { STANDARDS } from '@/components/homepage/sidebar-form/formConstants';
import useSidebarFormSubmit from '@/components/homepage/sidebar-form/useSidebarFormSubmit';
Expand All @@ -17,7 +17,7 @@ import { dictionary } from '@/libs/en';
export type SidebarFormSchema = z.infer<typeof schema>;

const schema = z.object({
standard: z.enum([STANDARDS.PSP22, STANDARDS.PSP37, STANDARDS.PSP34]),
standard: z.enum([STANDARDS.PSP22, STANDARDS.PSP34]),
name: z.string(),
symbol: z.string(),
decimals: z
Expand All @@ -27,9 +27,11 @@ const schema = z.object({
mintable: z.boolean(),
burnable: z.boolean(),
pausable: z.boolean(),
enumerable: z.boolean().optional(),
capped: z.boolean(),
accessControl: z.union([z.literal('security/ownable'), z.literal('security/control'), z.string().optional()]),
license: z.string()
license: z.string(),
isSingleCodeGenerationModeActive: z.boolean()
});

const defaultValues: SidebarFormSchema = {
Expand All @@ -39,10 +41,12 @@ const defaultValues: SidebarFormSchema = {
decimals: 0,
mintable: false,
burnable: false,
enumerable: false,
pausable: false,
capped: false,
accessControl: '',
license: ''
license: '',
isSingleCodeGenerationModeActive: false
};

export default function SidebarForm() {
Expand All @@ -53,11 +57,22 @@ export default function SidebarForm() {
});

const onSubmit = useSidebarFormSubmit();
const { handleSubmit, watch } = methods;
const { handleSubmit, watch, reset } = methods;
const watchedValues = watch();
const onSubmitHandler = handleSubmit(onSubmit);
const debouncedSubmit = debounce(onSubmitHandler, env.NEXT_PUBLIC_DEBOUNCE_INTERVAL_IN_MS);

const choosenStandard = watchedValues.standard;

// reset form after standard change but keep the standard value

useEffect(() => {
reset({
...defaultValues,
standard: watchedValues.standard
});
}, [choosenStandard]);

// initial data fetch form
useEffect(() => {
onSubmit(watchedValues).catch((err) => {
Expand All @@ -81,17 +96,13 @@ export default function SidebarForm() {
<h2 className="pb-6">{dictionary.sidebarForm.selectStandard}</h2>
<form onSubmit={handleSubmit(onSubmit)}>
<Standard />
<h2 className="py-6">{dictionary.sidebarForm.sections.singleFile.title}</h2>
<Switch name="isSingleCodeGenerationModeActive" disabled={choosenStandard === 'PSP34'} />
<h2 className="py-6">{dictionary.sidebarForm.configure}</h2>
{watchedValues.standard === STANDARDS.PSP22 ? (
<>
<Metadata />
<Features />
<AccessControl />
<License />
</>
) : (
<NotAvailable />
)}
<Metadata choosenStandard={choosenStandard} />
<Features choosenStandard={choosenStandard} />
<AccessControl choosenStandard={choosenStandard} />
<License />
</form>
</FormProvider>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { useFormContext } from 'react-hook-form';
import { Radio } from '@/components/data-entry/radio/Radio';
import ExpandableFilterContainer from '@/components/homepage/sidebar-form/ExpandableFilterContainer';
import { ACCESS_CONTROL } from '@/components/homepage/sidebar-form/formConstants';
import type { PSPUnion } from '@/components/homepage/sidebar-form/formConstants';
import { dictionary } from '@/libs/en';

export default function AccessControl() {
interface AccessControlProps {
choosenStandard: PSPUnion;
}

export default function AccessControl({ choosenStandard }: AccessControlProps) {
const { resetField } = useFormContext();

const handleResetAccessControlSection = () => {
Expand All @@ -17,7 +22,7 @@ export default function AccessControl() {
onReset={handleResetAccessControlSection}
>
<div className="pt-3">
<Radio options={ACCESS_CONTROL} name="accessControl" className="flex-col" />
<Radio options={ACCESS_CONTROL[choosenStandard]} name="accessControl" className="flex-col" />
</div>
</ExpandableFilterContainer>
);
Expand Down
Loading

0 comments on commit 58eea11

Please sign in to comment.