[questions][ui] updates

pull/411/head
Jeff Sieu 3 years ago
parent 634a41a48a
commit e8ba344ecb

@ -112,17 +112,7 @@ export default function QuestionCard({
const [showReceivedForm, setShowReceivedForm] = useState(false); const [showReceivedForm, setShowReceivedForm] = useState(false);
const { handleDownvote, handleUpvote, vote } = useQuestionVote(questionId); const { handleDownvote, handleUpvote, vote } = useQuestionVote(questionId);
const hoverClass = showHover ? 'hover:bg-slate-50' : ''; const hoverClass = showHover ? 'hover:bg-slate-50' : '';
const cardContent = showReceivedForm ? ( const cardContent = (
<CreateQuestionEncounterForm
onCancel={() => {
setShowReceivedForm(false);
}}
onSubmit={(data) => {
onReceivedSubmit?.(data);
setShowReceivedForm(false);
}}
/>
) : (
<> <>
{showVoteButtons && ( {showVoteButtons && (
<VotingButtons <VotingButtons
@ -132,7 +122,7 @@ export default function QuestionCard({
onUpvote={handleUpvote} onUpvote={handleUpvote}
/> />
)} )}
<div className="flex flex-col gap-2"> <div className="flex flex-col items-start gap-2">
<div className="flex items-baseline justify-between"> <div className="flex items-baseline justify-between">
<div className="flex items-baseline gap-2 text-slate-500"> <div className="flex items-baseline gap-2 text-slate-500">
<Badge label={company} variant="primary" /> <Badge label={company} variant="primary" />
@ -150,12 +140,10 @@ export default function QuestionCard({
/> />
)} )}
</div> </div>
<div className="ml-2"> <p className={clsx(truncateContent && 'line-clamp-2 text-ellipsis')}>
<p className={clsx(truncateContent && 'line-clamp-2 text-ellipsis')}> {content}
{content} </p>
</p> {!showReceivedForm && (showAnswerStatistics || showReceivedStatistics) && (
</div>
{(showAnswerStatistics || showReceivedStatistics) && (
<div className="flex gap-2"> <div className="flex gap-2">
{showAnswerStatistics && ( {showAnswerStatistics && (
<Button <Button
@ -190,6 +178,17 @@ export default function QuestionCard({
)} )}
</div> </div>
)} )}
{showReceivedForm && (
<CreateQuestionEncounterForm
onCancel={() => {
setShowReceivedForm(false);
}}
onSubmit={(data) => {
onReceivedSubmit?.(data);
setShowReceivedForm(false);
}}
/>
)}
</div> </div>
</> </>
); );

@ -21,7 +21,7 @@ export type QuestionListCardProps = Omit<
function QuestionListCardWithoutHref(props: QuestionListCardProps) { function QuestionListCardWithoutHref(props: QuestionListCardProps) {
return ( return (
<QuestionCard <QuestionCard
{...props} {...(props as any)}
showActionButton={false} showActionButton={false}
showAnswerStatistics={false} showAnswerStatistics={false}
showDeleteButton={true} showDeleteButton={true}

@ -2,7 +2,6 @@ import { startOfMonth } from 'date-fns';
import { useState } from 'react'; import { useState } from 'react';
import { Button } from '@tih/ui'; import { Button } from '@tih/ui';
import CompaniesTypeahead from '~/components/shared/CompaniesTypeahead';
import type { Month } from '~/components/shared/MonthYearPicker'; import type { Month } from '~/components/shared/MonthYearPicker';
import MonthYearPicker from '~/components/shared/MonthYearPicker'; import MonthYearPicker from '~/components/shared/MonthYearPicker';
@ -36,115 +35,113 @@ export default function CreateQuestionEncounterForm({
); );
return ( return (
<div> <div className="flex items-center gap-2">
<Button <p className="font-md text-md text-slate-600">I saw this question at</p>
label="Cancel" {step === 0 && (
variant="tertiary" <div>
onClick={(event) => { <CompanyTypeahead
event.preventDefault(); placeholder="Other company"
onCancel(); suggestedCount={3}
}} onSuggestionClick={({ value: company }) => {
/> setSelectedCompany(company);
<div className="flex items-center gap-2"> setStep(step + 1);
<p className="font-md text-md text-slate-600">I saw this question at</p>
{step === 0 && (
<div>
<CompanyTypeahead
placeholder="Other company"
suggestedCount={3}
onSuggestionClick={({ value: company }) => {
setSelectedCompany(company);
setStep(step + 1);
}}
isLabelHidden={true}
onSelect={({ value: company }) => {
setSelectedCompany(company);
}}
/>
</div>
)}
{step === 1 && (
<div>
<LocationTypeahead
suggestedCount={3}
onSuggestionClick={({ value: location }) => {
setSelectedLocation(location);
setStep(step + 1);
}}
isLabelHidden={true}
placeholder="Other location"
// eslint-disable-next-line @typescript-eslint/no-empty-function
onQueryChange={() => {}}
onSelect={({ value: location }) => {
setSelectedLocation(location);
}}
/>
</div>
)}
{step === 2 && (
<div>
<RoleTypeahead
isLabelHidden={true}
suggestedCount={3}
onSuggestionClick={({ value: role }) => {
setSelectedRole(role);
setStep(step + 1);
}}
placeholder="Other role"
// eslint-disable-next-line @typescript-eslint/no-empty-function
onQueryChange={() => {}}
onSelect={({ value: role }) => {
setSelectedRole(role);
}}
/>
</div>
)}
{step === 3 && (
<MonthYearPicker
yearLabel={''}
monthLabel={''}
value={{
month: ((selectedDate?.getMonth() ?? 0) + 1) as Month,
year: selectedDate?.getFullYear() as number,
}} }}
onChange={(value) => { isLabelHidden={true}
setSelectedDate( onSelect={({ value: company }) => {
startOfMonth(new Date(value.year, value.month - 1)), setSelectedCompany(company);
);
}} }}
/> />
)} </div>
{step < 3 && ( )}
<Button {step === 1 && (
label="Next" <div>
variant="primary" <LocationTypeahead
onClick={() => { suggestedCount={3}
onSuggestionClick={({ value: location }) => {
setSelectedLocation(location);
setStep(step + 1); setStep(step + 1);
}} }}
isLabelHidden={true}
placeholder="Other location"
// eslint-disable-next-line @typescript-eslint/no-empty-function
onQueryChange={() => {}}
onSelect={({ value: location }) => {
setSelectedLocation(location);
}}
/> />
)} </div>
{step === 3 && ( )}
<Button {step === 2 && (
label="Submit" <div>
variant="primary" <RoleTypeahead
onClick={() => { isLabelHidden={true}
if ( suggestedCount={3}
selectedCompany && onSuggestionClick={({ value: role }) => {
selectedLocation && setSelectedRole(role);
selectedRole && setStep(step + 1);
selectedDate }}
) { placeholder="Other role"
onSubmit({ // eslint-disable-next-line @typescript-eslint/no-empty-function
company: selectedCompany, onQueryChange={() => {}}
location: selectedLocation, onSelect={({ value: role }) => {
role: selectedRole, setSelectedRole(role);
seenAt: selectedDate,
});
}
}} }}
/> />
)} </div>
</div> )}
{step === 3 && (
<MonthYearPicker
yearLabel={''}
monthLabel={''}
value={{
month: ((selectedDate?.getMonth() ?? 0) + 1) as Month,
year: selectedDate?.getFullYear() as number,
}}
onChange={(value) => {
setSelectedDate(
startOfMonth(new Date(value.year, value.month - 1)),
);
}}
/>
)}
{step < 3 && (
<Button
label="Next"
variant="primary"
onClick={() => {
setStep(step + 1);
}}
/>
)}
{step === 3 && (
<Button
label="Submit"
variant="primary"
onClick={() => {
if (
selectedCompany &&
selectedLocation &&
selectedRole &&
selectedDate
) {
onSubmit({
company: selectedCompany,
location: selectedLocation,
role: selectedRole,
seenAt: selectedDate,
});
}
}}
/>
)}
<Button
label="Cancel"
variant="tertiary"
onClick={(event) => {
event.preventDefault();
onCancel();
}}
/>
</div> </div>
); );
} }

@ -1,7 +1,7 @@
import type { ComponentProps } from 'react'; import type { ComponentProps } from 'react';
import { Button, Typeahead } from '@tih/ui'; import { Button, Typeahead } from '@tih/ui';
type RequireAllOrNone<T> = T | { [K in keyof T]?: never }; import type { RequireAllOrNone } from '~/utils/questions/RequireAllOrNone';
type TypeaheadProps = ComponentProps<typeof Typeahead>; type TypeaheadProps = ComponentProps<typeof Typeahead>;
type TypeaheadOption = TypeaheadProps['options'][number]; type TypeaheadOption = TypeaheadProps['options'][number];

@ -0,0 +1 @@
export type RequireAllOrNone<T> = T | { [K in keyof T]?: never };
Loading…
Cancel
Save