mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-11 14:34:56 -05:00
* squash frontend changes * Style quest explorer * Style quest page * Dates * Dates * Typecheck * Prettier * Fix create page layout * Update only OPEN quests * Repetition info * Fix create quest errors * Quest form Textarea * Quest form Textarea * Truncate texts * Redirect if user not logged in * Tooltips * Factorize skills tags * fix username in completions * Metafam as default guild on creation * Layouts * Remove todo * cooldown * Rename to "claim quest" * squash frontend changes * Style quest explorer * Style quest page * Dates * Dates * Typecheck * Prettier * Fix create page layout * Update only OPEN quests * Repetition info * Fix create quest errors * Quest form Textarea * Quest form Textarea * Truncate texts * Redirect if user not logged in * Tooltips * Factorize skills tags * fix username in completions * Metafam as default guild on creation * Layouts * Remove todo * cooldown * Rename to "claim quest" * Move ConfirmModal in ds * Extract pSeed balance * Fix "created by me" switch * Reword complete quest * Style quest form * prettier * lint
95 lines
2.1 KiB
TypeScript
95 lines
2.1 KiB
TypeScript
import {
|
|
ConfirmModal,
|
|
HStack,
|
|
Input,
|
|
MetaButton,
|
|
Text,
|
|
VStack,
|
|
} from '@metafam/ds';
|
|
import {
|
|
CreateQuestCompletionInput,
|
|
QuestFragmentFragment,
|
|
} from 'graphql/autogen/types';
|
|
import { useRouter } from 'next/router';
|
|
import React, { useState } from 'react';
|
|
import { useForm } from 'react-hook-form';
|
|
|
|
import { UriRegexp } from '../../utils/questHelpers';
|
|
|
|
const validations = {
|
|
submission_text: {
|
|
required: true,
|
|
},
|
|
submission_link: {
|
|
pattern: UriRegexp,
|
|
},
|
|
};
|
|
|
|
type Props = {
|
|
quest: QuestFragmentFragment;
|
|
onSubmit: (data: CreateQuestCompletionInput) => void;
|
|
success?: boolean;
|
|
fetching?: boolean;
|
|
};
|
|
|
|
export const CompletionForm: React.FC<Props> = ({
|
|
quest,
|
|
onSubmit,
|
|
success,
|
|
fetching,
|
|
}) => {
|
|
const { register, errors, handleSubmit } = useForm<
|
|
CreateQuestCompletionInput
|
|
>();
|
|
const [exitAlert, setExitAlert] = useState<boolean>(false);
|
|
const router = useRouter();
|
|
|
|
return (
|
|
<VStack>
|
|
<Text>Description</Text>
|
|
<Input
|
|
background="dark"
|
|
placeholder="What did you do ?"
|
|
isRequired
|
|
name="submission_text"
|
|
ref={register(validations.submission_text)}
|
|
isInvalid={!!errors.submission_text}
|
|
/>
|
|
|
|
<Text>Link</Text>
|
|
<Input
|
|
background="dark"
|
|
placeholder="External link"
|
|
name="submission_link"
|
|
ref={register(validations.submission_link)}
|
|
isInvalid={!!errors.submission_link}
|
|
/>
|
|
<HStack>
|
|
<MetaButton
|
|
variant="outline"
|
|
onClick={() => setExitAlert(true)}
|
|
isDisabled={fetching || success}
|
|
>
|
|
Cancel
|
|
</MetaButton>
|
|
<MetaButton
|
|
mt={10}
|
|
isLoading={fetching}
|
|
loadingText="Submitting..."
|
|
onClick={handleSubmit(onSubmit)}
|
|
isDisabled={success}
|
|
>
|
|
Submit
|
|
</MetaButton>
|
|
</HStack>
|
|
|
|
<ConfirmModal
|
|
isOpen={exitAlert}
|
|
onNope={() => setExitAlert(false)}
|
|
onYep={() => router.push(`/quest/${quest.id}`)}
|
|
header="Are you sure you want to leave ?"
|
|
/>
|
|
</VStack>
|
|
);
|
|
};
|