|
|
|
@ -1,24 +1,14 @@
|
|
|
|
|
import { startOfMonth } from 'date-fns';
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { Controller, useForm } from 'react-hook-form';
|
|
|
|
|
import { ArrowPathIcon } from '@heroicons/react/20/solid';
|
|
|
|
|
import type { QuestionsQuestionType } from '@prisma/client';
|
|
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
CheckboxInput,
|
|
|
|
|
HorizontalDivider,
|
|
|
|
|
Select,
|
|
|
|
|
TextArea,
|
|
|
|
|
} from '@tih/ui';
|
|
|
|
|
import { Button, HorizontalDivider, Select, TextArea } from '@tih/ui';
|
|
|
|
|
|
|
|
|
|
import { LOCATIONS, QUESTION_TYPES, ROLES } from '~/utils/questions/constants';
|
|
|
|
|
import {
|
|
|
|
|
useFormRegister,
|
|
|
|
|
useSelectRegister,
|
|
|
|
|
} from '~/utils/questions/useFormRegister';
|
|
|
|
|
import { trpc } from '~/utils/trpc';
|
|
|
|
|
|
|
|
|
|
import SimilarQuestionCard from '../card/question/SimilarQuestionCard';
|
|
|
|
|
import CompanyTypeahead from '../typeahead/CompanyTypeahead';
|
|
|
|
|
import LocationTypeahead from '../typeahead/LocationTypeahead';
|
|
|
|
|
import RoleTypeahead from '../typeahead/RoleTypeahead';
|
|
|
|
@ -48,39 +38,15 @@ export default function ContributeQuestionForm({
|
|
|
|
|
control,
|
|
|
|
|
register: formRegister,
|
|
|
|
|
handleSubmit,
|
|
|
|
|
watch,
|
|
|
|
|
} = useForm<ContributeQuestionData>({
|
|
|
|
|
defaultValues: {
|
|
|
|
|
date: startOfMonth(new Date()),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [contentToCheck, setContentToCheck] = useState('');
|
|
|
|
|
|
|
|
|
|
const { data: similarQuestions } = trpc.useQuery(
|
|
|
|
|
[
|
|
|
|
|
'questions.questions.getRelatedQuestionsByContent',
|
|
|
|
|
{ content: contentToCheck },
|
|
|
|
|
],
|
|
|
|
|
{
|
|
|
|
|
keepPreviousData: true,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
const questionContent = watch('questionContent');
|
|
|
|
|
const register = useFormRegister(formRegister);
|
|
|
|
|
const selectRegister = useSelectRegister(formRegister);
|
|
|
|
|
|
|
|
|
|
const [checkedSimilar, setCheckedSimilar] = useState<boolean>(false);
|
|
|
|
|
const handleCheckSimilarQuestions = (checked: boolean) => {
|
|
|
|
|
setCheckedSimilar(checked);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (questionContent !== contentToCheck) {
|
|
|
|
|
setCheckedSimilar(false);
|
|
|
|
|
}
|
|
|
|
|
}, [questionContent, contentToCheck]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col justify-between gap-4">
|
|
|
|
|
<form
|
|
|
|
@ -180,63 +146,12 @@ export default function ContributeQuestionForm({
|
|
|
|
|
<div className="w-full">
|
|
|
|
|
<HorizontalDivider />
|
|
|
|
|
</div>
|
|
|
|
|
<h2
|
|
|
|
|
className="text-primary-900 mb-3
|
|
|
|
|
text-lg font-semibold
|
|
|
|
|
">
|
|
|
|
|
Are these questions the same as yours?
|
|
|
|
|
</h2>
|
|
|
|
|
<Button
|
|
|
|
|
addonPosition="start"
|
|
|
|
|
disabled={questionContent === contentToCheck}
|
|
|
|
|
icon={ArrowPathIcon}
|
|
|
|
|
label="Refresh similar questions"
|
|
|
|
|
variant="primary"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setContentToCheck(questionContent);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<div className="flex flex-col gap-y-2">
|
|
|
|
|
{similarQuestions?.map((question) => (
|
|
|
|
|
<SimilarQuestionCard
|
|
|
|
|
key={question.id}
|
|
|
|
|
content={question.content}
|
|
|
|
|
questionId={question.id}
|
|
|
|
|
timestamp={
|
|
|
|
|
question.lastSeenAt?.toLocaleDateString(undefined, {
|
|
|
|
|
month: 'short',
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
}) ?? null
|
|
|
|
|
}
|
|
|
|
|
type={question.questionType}
|
|
|
|
|
onSimilarQuestionClick={() => {
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
|
console.log('hi!');
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
{similarQuestions?.length === 0 && (
|
|
|
|
|
<p className="text-slate-900 font-semibold">No similar questions found.</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className="bg-primary-50 flex w-full flex-col gap-y-2 py-3 shadow-[0_0_0_100vmax_theme(colors.primary.50)] sm:flex-row sm:justify-between"
|
|
|
|
|
className="bg-primary-50 flex w-full justify-end gap-y-2 py-3 shadow-[0_0_0_100vmax_theme(colors.primary.50)]"
|
|
|
|
|
style={{
|
|
|
|
|
// Hack to make the background bleed outside the container
|
|
|
|
|
clipPath: 'inset(0 -100vmax)',
|
|
|
|
|
}}>
|
|
|
|
|
<div className="my-2 flex items-center sm:my-0">
|
|
|
|
|
<CheckboxInput
|
|
|
|
|
disabled={questionContent !== contentToCheck}
|
|
|
|
|
label={
|
|
|
|
|
questionContent !== contentToCheck
|
|
|
|
|
? 'I have checked that my question is new (Refresh similar questions to proceed)'
|
|
|
|
|
: 'I have checked that my question is new'
|
|
|
|
|
}
|
|
|
|
|
value={checkedSimilar}
|
|
|
|
|
onChange={handleCheckSimilarQuestions}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex gap-x-2">
|
|
|
|
|
<button
|
|
|
|
|
className="focus:ring-primary-500 inline-flex w-full justify-center rounded-md border border-slate-300 bg-white px-4 py-2 text-base font-medium text-slate-700 shadow-sm hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-offset-2 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm"
|
|
|
|
@ -246,7 +161,6 @@ export default function ContributeQuestionForm({
|
|
|
|
|
</button>
|
|
|
|
|
<Button
|
|
|
|
|
className="bg-primary-600 hover:bg-primary-700 focus:ring-primary-500 inline-flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-base font-medium text-white shadow-sm focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:bg-slate-400 sm:ml-3 sm:w-auto sm:text-sm"
|
|
|
|
|
disabled={!checkedSimilar}
|
|
|
|
|
label="Contribute"
|
|
|
|
|
type="submit"
|
|
|
|
|
variant="primary"></Button>
|
|
|
|
|