Skip to content

Commit

Permalink
fix: naming errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam-Zhao committed Aug 18, 2023
1 parent bc515a0 commit 9ab57c0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/components/clusters/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export default function EditCluster() {
name: 'bio',
autoComplete: 'family-name',
value: bio,
placeholder: 'Please enter Description',
helperText: bioError ? 'Must be a number and range from 0-1000' : '',
placeholder: 'Please enter description',
helperText: bioError ? 'The length is 1-1000' : '',
error: bioError,

onChange: (e: any) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/clusters/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function NewCluster() {
name: 'description',
autoComplete: 'family-name',
placeholder: 'Enter a cluster description',
helperText: bioError ? 'The length is 0-40' : '',
helperText: bioError ? 'The length is 1-1000' : '',
error: bioError,

onChange: (e: any) => {
Expand Down Expand Up @@ -386,7 +386,7 @@ export default function NewCluster() {

event.preventDefault();
const data = new FormData(event.currentTarget);

const name = event.currentTarget.elements.name.value;
const isDefault = event.currentTarget.elements.isDefault.checked;
const description = event.currentTarget.elements.description.value;
Expand Down
31 changes: 16 additions & 15 deletions src/components/developer/tokens/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ export default function UpdateTokens() {
const [preheat, setPreheat] = useState(false);
const [job, setJob] = useState(false);
const [loadingButton, setLoadingButton] = useState(false);
const [token, setToken] = useState({ name: '', bio: '', scopes: [''], expired_at: '', state: '', id: 0 });
const [tokens, setTokens] = useState({ name: '', bio: '', scopes: [''], expired_at: '', state: '', id: 0 });

const formList = [
{
formProps: {
id: 'Bio',
id: 'bio',
label: 'Description',
name: 'Bio',
name: 'bio',
autoComplete: 'family-name',
placeholder: 'Enter your Note',
value: token.bio,
helperText: bioError ? 'Please enter Description' : '',
placeholder: 'Enter your description',
value: tokens.bio,
helperText: bioError ? 'The length is 1-1000' : '',
error: bioError,

InputProps: {
Expand All @@ -71,7 +72,7 @@ export default function UpdateTokens() {
},

onChange: (e: any) => {
setToken({ ...token, bio: e.target.value });
setTokens({ ...tokens, bio: e.target.value });
changeValidate(e.target.value, formList[0]);
},
},
Expand All @@ -92,11 +93,11 @@ export default function UpdateTokens() {
(async function () {
try {
if (params?.id) {
const token = await getToken(params?.id);
setToken(token);
setExpiredTime(token.expired_at);
setPreheat(token.scopes.includes('preheat'));
setJob(token.scopes.includes('job'));
const tokens = await getToken(params?.id);
setTokens(tokens);
setExpiredTime(tokens.expired_at);
setPreheat(tokens.scopes.includes('preheat'));
setJob(tokens.scopes.includes('job'));
}
} catch (error) {
if (error instanceof Error) {
Expand Down Expand Up @@ -137,7 +138,7 @@ export default function UpdateTokens() {

const canSubmit = Boolean(!formList.filter((item) => item.syncError).length);

const formData = { bio: token.bio, expired_at: expiredTime, scopes: filteredScopes };
const formData = { bio: tokens.bio, expired_at: expiredTime, scopes: filteredScopes };

if (!selectedTime) {
setExpiredTimeError(true);
Expand All @@ -146,11 +147,11 @@ export default function UpdateTokens() {
if (canSubmit) {
try {
if (params.id) {
const response = await updateTokens(params.id, { ...formData });
const tokens = await updateTokens(params.id, { ...formData });
setLoadingButton(false);
setSuccessMessage(true);

const token = response.token;
const token = tokens.token;
localStorage.setItem('token', JSON.stringify(token));
navigate('/developer/personal-access-tokens');
}
Expand Down
16 changes: 8 additions & 8 deletions src/components/developer/tokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function PersonalAccessTokens() {
const [openDeletToken, setOpenDeletToken] = useState(false);
const [deleteLoadingButton, setDeleteLoadingButton] = useState(false);
const [tokenSelectedID, setTokenSelectedID] = useState('');
const [token, setToken] = useState([
const [tokens, setTokens] = useState([
{ name: '', id: 0, scopes: [''], token: '', created_at: '', expired_at: '', user: { name: '' } },
]);
const [showCopyColumn, setShowCopyColumn] = useState(false);
Expand All @@ -58,11 +58,11 @@ export default function PersonalAccessTokens() {
try {
if (user.name === 'root') {
const token = await getTokens();
setToken(token);
setTokens(token);
setIsLoading(false);
} else if (user.name !== '') {
const token = await getTokens({ user_id: String(user.id) });
setToken(token);
setTokens(token);
setIsLoading(false);
}
} catch (error) {
Expand Down Expand Up @@ -90,11 +90,11 @@ export default function PersonalAccessTokens() {
setOpenDeletToken(false);

if (user.name === 'root') {
const token = await getTokens();
setToken(token);
const tokens = await getTokens();
setTokens(tokens);
} else if (user.name !== '') {
const token = await getTokens({ user_id: String(user.id) });
setToken(token);
setTokens(token);
}
} catch (error) {
if (error instanceof Error) {
Expand Down Expand Up @@ -215,8 +215,8 @@ export default function PersonalAccessTokens() {
) : (
<></>
)}
{Array.isArray(token) &&
token.map((item) => {
{Array.isArray(tokens) &&
tokens.map((item) => {
return (
<Box key={item.id}>
<Box sx={{ display: 'flex', p: '0.8rem', justifyContent: 'space-between', alignItems: 'center' }}>
Expand Down
13 changes: 7 additions & 6 deletions src/components/developer/tokens/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ export default function CreateTokens() {
const [preheat, setPreheat] = useState(false);
const [job, setJob] = useState(false);
const [loadingButton, setLoadingButton] = useState(false);

const formList = [
{
formProps: {
id: 'name',
label: 'Name',
name: 'name',
autoComplete: 'family-name',
placeholder: 'Enter your token',
placeholder: 'Enter your token name',
helperText: nameError ? 'Please enter the correct token name' : '',
error: nameError,
InputProps: {
Expand Down Expand Up @@ -82,12 +83,12 @@ export default function CreateTokens() {
},
{
formProps: {
id: 'Bio',
id: 'bio',
label: 'Description',
name: 'bio',
autoComplete: 'family-name',
placeholder: 'Enter your Description',
helperText: bioError ? 'Please enter Description' : '',
placeholder: 'Enter your description',
helperText: bioError ? 'The length is 1-1000' : '',
error: bioError,
InputProps: {
endAdornment: (
Expand Down Expand Up @@ -162,11 +163,11 @@ export default function CreateTokens() {

if (canSubmit) {
try {
const response = await createTokens({ ...formData });
const tokens = await createTokens({ ...formData });
setLoadingButton(false);
setSuccessMessage(true);

const token = response.token;
const token = tokens.token;
localStorage.setItem('token', JSON.stringify(token));
navigate('/developer/personal-access-tokens');
} catch (error) {
Expand Down

0 comments on commit 9ab57c0

Please sign in to comment.