-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1198 from Chia-Network/refactor/my-organization
Refactor/my organization
- Loading branch information
Showing
31 changed files
with
811 additions
and
127 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 10 additions & 8 deletions
18
src/renderer/components/blocks/buttons/QueryRefetchButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import React from "react"; | ||
import {Button} from "@/components"; | ||
import {FormattedMessage} from "react-intl"; | ||
import React from 'react'; | ||
import { Button } from '@/components'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
interface QueryRefetchButtonProps { | ||
onRefetch: () => void; | ||
} | ||
|
||
const QueryRefetchButton: React.FC<QueryRefetchButtonProps> = ({onRefetch}) => { | ||
const QueryRefetchButton: React.FC<QueryRefetchButtonProps> = ({ onRefetch }) => { | ||
return ( | ||
<Button | ||
onClick={() => {onRefetch()}} | ||
onClick={() => { | ||
onRefetch(); | ||
}} | ||
> | ||
<FormattedMessage id={"unable-to-load-click-to-retry"} /> | ||
<FormattedMessage id="unable-to-load-click-to-retry" /> | ||
</Button> | ||
); | ||
} | ||
}; | ||
|
||
export {QueryRefetchButton}; | ||
export { QueryRefetchButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/renderer/components/blocks/forms/CreateOrganizationForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useCallback } from 'react'; | ||
import { ErrorMessage, Field, Form, Formik } from 'formik'; | ||
import * as yup from 'yup'; | ||
import { Button, FloatingLabel, Spinner } from '@/components'; | ||
import { IntlShape, useIntl } from 'react-intl'; | ||
|
||
const validationSchema = yup.object({ | ||
name: yup.string().required('Name is required'), | ||
}); | ||
|
||
interface FormProps { | ||
onSubmit: (orgName: string) => Promise<any>; | ||
} | ||
|
||
const CreateOrganizationForm: React.FC<FormProps> = ({ onSubmit }) => { | ||
const intl: IntlShape = useIntl(); | ||
|
||
const handleSubmit = useCallback( | ||
async (values: { name: string }, { setSubmitting }) => { | ||
await onSubmit(values.name); | ||
setSubmitting(false); | ||
}, | ||
[onSubmit], | ||
); // Include onSuccess in the dependencies array | ||
|
||
return ( | ||
<Formik initialValues={{ name: '' }} validationSchema={validationSchema} onSubmit={handleSubmit}> | ||
{({ errors, touched, isSubmitting }) => ( | ||
<Form> | ||
<div className="mb-4"> | ||
<Field name="name"> | ||
{({ field }) => ( | ||
<FloatingLabel | ||
id="name" | ||
label={intl.formatMessage({ id: 'organization-name' })} | ||
color={errors.name && touched.name && 'error'} | ||
variant="outlined" | ||
type="text" | ||
{...field} | ||
/> | ||
)} | ||
</Field> | ||
{touched.name && <ErrorMessage name="name" component="div" className="text-red-600" />} | ||
</div> | ||
<Button type="submit" disabled={isSubmitting}> | ||
{isSubmitting ? <Spinner size="sm" light={true} /> : 'Submit'} | ||
</Button> | ||
</Form> | ||
)} | ||
</Formik> | ||
); | ||
}; | ||
|
||
export { CreateOrganizationForm }; |
87 changes: 87 additions & 0 deletions
87
src/renderer/components/blocks/forms/EditOrganizationForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { useCallback } from 'react'; | ||
import { ErrorMessage, Field, Form, Formik } from 'formik'; | ||
import * as yup from 'yup'; | ||
import { Button, FormButton, TextInput } from '@/components'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Organization } from '@/schemas/Organization.schema'; | ||
|
||
const validationSchema = yup.object({ | ||
organizationName: yup.string().required('The organization name must be at least 3 characters').min(3), | ||
}); | ||
|
||
interface FormProps { | ||
myOrganization: Organization; | ||
onSubmit: (organizationName: string) => Promise<any>; | ||
onCancel: () => void; | ||
} | ||
|
||
const EditOrganizationForm: React.FC<FormProps> = ({ myOrganization, onSubmit, onCancel }: FormProps) => { | ||
const handleSubmit = useCallback( | ||
async (values: { organizationName: string }, { setSubmitting }) => { | ||
await onSubmit(values.organizationName); | ||
setSubmitting(false); | ||
}, | ||
[onSubmit], | ||
); | ||
|
||
const handleChange = useCallback((event, field) => { | ||
field.onChange(event); // Call Formik's original onChange | ||
}, []); | ||
|
||
return ( | ||
<Formik | ||
initialValues={{ organizationName: myOrganization.name }} | ||
validationSchema={validationSchema} | ||
onSubmit={handleSubmit} | ||
> | ||
{({ errors, touched, isSubmitting }) => ( | ||
<Form> | ||
<div className="mb-4"> | ||
<Field name="organizationName"> | ||
{({ field }) => ( | ||
<div className="flex justify-start align-middle"> | ||
<div> | ||
<p className="font-bold text-left text-gray-700 dark:text-gray-400 mr-4"> | ||
<FormattedMessage id="name" /> | ||
</p> | ||
</div> | ||
<TextInput | ||
className="w-3/5 mb-2" | ||
id="organizationName" | ||
color={errors.organizationName && touched.organizationName && 'failure'} | ||
variant="outlined" | ||
required | ||
type="text" | ||
{...field} | ||
onChange={(event) => handleChange(event, field)} | ||
/> | ||
</div> | ||
)} | ||
</Field> | ||
{touched.organizationName && ( | ||
<ErrorMessage name="organizationName" component="div" className="text-red-600" /> | ||
)} | ||
<div className="flex justify-start"> | ||
<p className="font-bold text-left text-gray-700 dark:text-gray-400 mr-4"> | ||
<FormattedMessage id="orguid" /> | ||
</p> | ||
<p className="font-normal text-left text-gray-700 dark:text-gray-400 inline-block"> | ||
{myOrganization.orgUid} | ||
</p> | ||
</div> | ||
</div> | ||
<div className="space-x-2 flex"> | ||
<FormButton isSubmitting={isSubmitting} formikErrors={errors}> | ||
<FormattedMessage id="save" /> | ||
</FormButton> | ||
<Button onClick={onCancel} color="gray"> | ||
<FormattedMessage id="cancel" /> | ||
</Button> | ||
</div> | ||
</Form> | ||
)} | ||
</Formik> | ||
); | ||
}; | ||
|
||
export { EditOrganizationForm }; |
56 changes: 56 additions & 0 deletions
56
src/renderer/components/blocks/forms/ImportOrganizationForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useCallback } from 'react'; | ||
import { ErrorMessage, Field, Form, Formik } from 'formik'; | ||
import * as yup from 'yup'; | ||
import { Button, FloatingLabel, Spinner } from '@/components'; | ||
import { IntlShape, useIntl } from 'react-intl'; | ||
|
||
const validationSchema = yup.object({ | ||
orgUid: yup.string().length(64).required('OrgUid is required'), | ||
}); | ||
|
||
interface FormProps { | ||
onSubmit: (orgUid: string) => Promise<any>; | ||
} | ||
|
||
const ImportOrganizationForm: React.FC<FormProps> = ({ onSubmit }) => { | ||
const intl: IntlShape = useIntl(); | ||
|
||
const handleSubmit = useCallback( | ||
async (values: { orgUid: string }, { setSubmitting }) => { | ||
await onSubmit(values.orgUid); | ||
setSubmitting(false); | ||
}, | ||
[onSubmit], | ||
); // Include onSuccess in the dependencies array | ||
|
||
return ( | ||
<> | ||
<Formik initialValues={{ orgUid: '' }} validationSchema={validationSchema} onSubmit={handleSubmit}> | ||
{({ errors, touched, isSubmitting }) => ( | ||
<Form> | ||
<div className="mb-4"> | ||
<Field name="orgUid"> | ||
{({ field }) => ( | ||
<FloatingLabel | ||
id="name" | ||
label={intl.formatMessage({ id: 'organization-orguid' })} | ||
color={errors.orgUid && touched.orgUid && 'error'} | ||
variant="outlined" | ||
type="text" | ||
{...field} | ||
/> | ||
)} | ||
</Field> | ||
{touched.orgUid && <ErrorMessage name="orgUid" component="div" className="text-red-600" />} | ||
</div> | ||
<Button type="submit" disabled={isSubmitting}> | ||
{isSubmitting ? <Spinner size="sm" light={true} /> : 'Submit'} | ||
</Button> | ||
</Form> | ||
)} | ||
</Formik> | ||
</> | ||
); | ||
}; | ||
|
||
export { ImportOrganizationForm }; |
Oops, something went wrong.