umami/components/pages/settings/teams/JoinTeamForm.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-02-02 03:39:54 +01:00
import { useRef } from 'react';
import {
Form,
FormRow,
FormInput,
FormButtons,
TextField,
Button,
SubmitButton,
} from 'react-basics';
import useApi from 'hooks/useApi';
2023-03-22 22:05:55 +01:00
import useMessages from 'hooks/useMessages';
2023-02-02 03:39:54 +01:00
export default function TeamJoinForm({ onSave, onClose }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, labels, getMessage } = useMessages();
2023-02-02 03:39:54 +01:00
const { post, useMutation } = useApi();
const { mutate, error } = useMutation(data => post('/teams/join', data));
const ref = useRef(null);
const handleSubmit = async data => {
mutate(data, {
onSuccess: async () => {
onSave();
onClose();
},
});
};
return (
2023-03-22 22:05:55 +01:00
<Form ref={ref} onSubmit={handleSubmit} error={error && getMessage(error)}>
2023-02-02 03:39:54 +01:00
<FormRow label={formatMessage(labels.accessCode)}>
<FormInput name="accessCode" rules={{ required: formatMessage(labels.required) }}>
<TextField autoComplete="off" />
</FormInput>
</FormRow>
<FormButtons flex>
<SubmitButton variant="primary">{formatMessage(labels.join)}</SubmitButton>
<Button onClick={onClose}>{formatMessage(labels.cancel)}</Button>
</FormButtons>
</Form>
);
}