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

Update sdk to v2 #3207

Merged
merged 23 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 3 additions & 1 deletion packages/tokens-studio-for-figma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@supabase/supabase-js": "^2.0.5",
"@supernovaio/supernova-sdk": "^1.9.3",
"@tokens-studio/graph-engine": "^0.17.5",
"@tokens-studio/sdk": "^1.2.1",
"@tokens-studio/sdk": "^2.0.0-alpha.0",
"@tokens-studio/tokens": "0.2.5",
"@tokens-studio/types": "0.5.1",
"@tokens-studio/ui": "0.9.0",
Expand Down Expand Up @@ -92,6 +92,7 @@
"i18next": "^23.2.3",
"iconoir-react": "^7.3.0",
"ignore-styles": "^5.0.1",
"is-plain-obj": "^4.1.0",
"js-yaml": "^4.1.0",
"json5": "^2.2.3",
"jszip": "^3.10.0",
Expand Down Expand Up @@ -138,6 +139,7 @@
"rooks": "^6.4.2",
"set-value": "^3.0.3",
"storyblok-js-client": "^3.3.1",
"style-dictionary": "^4.2.0",
"use-debounce": "^6.0.1",
"uuid": "^9.0.0",
"zod": "^3.22.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import React from 'react';
import React, { useEffect } from 'react';
import zod from 'zod';
import {
Box, Button, FormField, Heading, IconButton, Label, Link, Stack, Text, TextInput,
Box,
Button,
FormField,
Heading,
IconButton,
Label,
Link,
Select,
Stack,
Text,
TextInput,
} from '@tokens-studio/ui';
import { EyeClosedIcon, EyeOpenIcon } from '@radix-ui/react-icons';
import { useTranslation } from 'react-i18next';
import { create, Organization } from '@tokens-studio/sdk';
import { StorageProviderType } from '@/constants/StorageProviderType';
import { StorageTypeFormValues } from '@/types/StorageType';
import { generateId } from '@/utils/generateId';
import { ChangeEventHandler } from './types';
import { ErrorMessage } from '../ErrorMessage';
import TokensStudioWord from '@/icons/tokensstudio-word.svg';
import { styled } from '@/stitches.config';
import { GET_ORGS_QUERY } from '@/storage/tokensStudio/graphql';

const StyledTokensStudioWord = styled(TokensStudioWord, {
width: '200px',
Expand All @@ -28,10 +40,10 @@
errorMessage?: string;
};

export default function TokensStudioForm({
onChange, onSubmit, onCancel, values, hasErrored, errorMessage,
}: Props) {
export default function TokensStudioForm({ onChange, onSubmit, onCancel, values, hasErrored, errorMessage }: Props) {

Check failure

Code scanning / ESLint

enforce consistent line breaks after opening and before closing braces Error

Expected a line break after this opening brace.

Check failure

Code scanning / ESLint

enforce consistent line breaks after opening and before closing braces Error

Expected a line break before this closing brace.
const { t } = useTranslation(['storage']);
const [fetchOrgsError, setFetchOrgsError] = React.useState<string | null>(null);
const [orgData, setOrgData] = React.useState<Organization[]>([]);
const syncGuideUrl = 'tokens-studio';
const [isMasked, setIsMasked] = React.useState(true);
const [showTeaser, setShowTeaser] = React.useState(true);
Expand All @@ -50,6 +62,7 @@
id: zod.string(),
secret: zod.string(),
internalId: zod.string().optional(),
orgId: zod.string(),
});
const validationResult = zodSchema.safeParse(values);
if (validationResult.success) {
Expand All @@ -73,20 +86,87 @@
setShowTeaser(false);
}, []);

return showTeaser ? (
<Stack direction="column" align="start" gap={5}>
<StyledTokensStudioWord />
<Stack direction="column" gap={3}>
<Heading size="large">A dedicated design tokens management platform</Heading>
<Box>We are working a dedicated design tokens management platform built on our powerful node-based graph engine including plug and play token transformation - suitable for enterprises! Still in early access, sign up for the waitlist!</Box>
<Link href="https://tokens.studio/studio" target="_blank" rel="noreferrer">Learn more</Link>
</Stack>
<Button onClick={handleDismissTeaser}>Already got access?</Button>
useEffect(() => {
if (values.secret) {
fetchOrgData();
Fixed Show fixed Hide fixed
}
}, [values.secret]);
Fixed Show fixed Hide fixed

const fetchOrgData = React.useCallback(async () => {
try {
const client = create({
host: process.env.API_HOST || 'localhost:4200',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the Studio API? Lets change the name of the env variable then to Studio

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

secure: process.env.NODE_ENV !== 'development',
auth: `Bearer ${values.secret}`,
});
const result = await client.query({
query: GET_ORGS_QUERY,
});
if (result.data?.organizations) {
setOrgData(result.data.organizations.data as Organization[]);
}
} catch (error) {
setFetchOrgsError('Error fetching organization data. Please check your PAT.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets write the full name not PAT

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}
}, [values.secret]);

const orgOptions = React.useMemo(
() =>
orgData?.map((org) => ({

Check failure

Code scanning / ESLint

enforce the location of arrow function bodies Error

Expected no linebreak before this expression.
label: org.name,
value: org.id,
})),
[orgData],
);

const onOrgChange = React.useCallback(
(value: string) => {
onChange({ target: { name: 'orgId', value } });
},
[onChange],
);

const projectOptions = React.useMemo(() => {
if (!orgData) return [];
const org = orgData.find((org) => org.id === values.orgId);
Fixed Show fixed Hide fixed
if (!org) return [];
return org.projects.data.map((project) => ({
label: project.name,
value: project.id,
}));
}, [orgData, values.orgId]);

const selectedOrg = orgOptions?.find((org) => org.value === values.orgId);

const selectedProject = projectOptions?.find((project) => project.value === values.id);

const onProjectChange = React.useCallback(
(value: string) => {
onChange({ target: { name: 'id', value } });
},
[onChange],
);

return showTeaser ? (
<Stack direction="column" align="start" gap={5}>
<StyledTokensStudioWord />
<Stack direction="column" gap={3}>
<Heading size="large">A dedicated design tokens management platform</Heading>
<Box>
We are working a dedicated design tokens management platform built on our powerful node-based graph engine
including plug and play token transformation - suitable for enterprises! Still in early access, sign up for
the waitlist!
</Box>
<Link href="https://tokens.studio/studio" target="_blank" rel="noreferrer">
Learn more
</Link>
</Stack>
):(
<Button onClick={handleDismissTeaser}>Already got access?</Button>
</Stack>
) : (
<form onSubmit={handleSubmit}>
<Stack direction="column" gap={5}>
<Text muted>
<Text muted>
{t('providers.tokensstudio.descriptionFirstPart')}{' '}
<Link
href="https://q2gsw2tok1e.typeform.com/to/pJCwLVh2?typeform-source=tokens.studio"
Expand Down Expand Up @@ -118,22 +198,55 @@
onChange={onChange}
name="secret"
id="secret"
onBlur={fetchOrgData}
required
type={isMasked ? 'password' : 'text'}
trailingAction={(
trailingAction={
<IconButton
variant="invisible"
size="small"
onClick={toggleMask}
icon={isMasked ? <EyeClosedIcon /> : <EyeOpenIcon />}
/>
)}
}
/>
{fetchOrgsError && <Text muted>{fetchOrgsError}</Text>}
</FormField>
<FormField>
<Label htmlFor="id">{t('providers.tokensstudio.id')}</Label>
<TextInput value={values.id || ''} onChange={onChange} type="text" name="id" id="id" required />
</FormField>
{orgOptions?.length > 0 && (
<Stack direction="column" gap={2}>
<Label htmlFor="org">{t('providers.tokensstudio.selectOrgLabel')}</Label>
<div>
<Select value={values.orgId ?? ''} onValueChange={onOrgChange} name="org">
<Select.Trigger value={selectedOrg?.label || 'Choose an organization'} />
<Select.Content>
{orgOptions?.map((option) => (
<Select.Item key={option.value} value={option.value}>
{option.label}
</Select.Item>
))}
</Select.Content>
</Select>
</div>
</Stack>
)}

{projectOptions?.length > 0 && (
<Stack direction="column" gap={2}>
<Label htmlFor="org">{t('providers.tokensstudio.selectProjectLabel')}</Label>
<div>
<Select value={values.id ?? ''} onValueChange={onProjectChange} name="id">
<Select.Trigger value={selectedProject?.label || 'Choose a project'} />
<Select.Content>
{projectOptions?.map((option) => (
<Select.Item key={option.value} value={option.value}>
{option.label}
</Select.Item>
))}
</Select.Content>
</Select>
</div>
</Stack>
)}
<Stack direction="row" justify="end" gap={4}>
<Button variant="secondary" onClick={onCancel}>
{t('cancel')}
Expand Down
Loading
Loading