Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue 538 🔥 #549

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 42 additions & 58 deletions apps/member-profile/app/shared/components/ethnicity-combobox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useFetcher } from '@remix-run/react';

import { useEffect } from 'react';

import {
Expand All @@ -17,103 +18,86 @@ import {

import type { SearchCountriesResult } from '@/routes/api.countries.search';

// Ethnicity Combobox
type EthnicityComboboxProps = Pick<InputProps, 'name' | 'required'>;

export function EthnicityCombobox({ name }: EthnicityComboboxProps) {
const fetcher = useFetcher<SearchCountriesResult>();

useEffect(() => {
fetcher.load('/api/countries/search');
}, []);
}, [fetcher]);

const countries = fetcher.data?.countries || [];

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
fetcher.submit(
{ search: e.currentTarget.value },
{
action: '/api/countries/search',
method: 'get',
}
);
};

return (
<Combobox>
<ComboboxInput
id={name}
name={name}
onChange={(e) => {
fetcher.submit(
{ search: e.currentTarget.value },
{
action: '/api/countries/search',
method: 'get',
}
);
}}
required
/>
<ComboboxInput id={name} name={name} onChange={handleInputChange} required />

{!!countries.length && (
<ComboboxPopover>
<ul>
{countries.map((country) => {
const label = `${country.flagEmoji} ${country.demonym}`;

return (
<ComboboxItem key={country.code} value={country.code}>
{label}
</ComboboxItem>
);
})}
</ul>
<div className="max-h-48 overflow-y-auto">
{countries.map((country) => (
<ComboboxItem key={country.code} value={country.code}>
{`${country.flagEmoji} ${country.demonym}`}
</ComboboxItem>
))}
</div>
</ComboboxPopover>
)}
</Combobox>
);
}

// Ethnicity MultiCombobox
type EthnicityMultiComboboxProps = Pick<MultiComboboxProps, 'defaultValues'> &
Pick<InputProps, 'name' | 'required'>;

export function EthnicityMultiCombobox({
defaultValues,
name,
}: EthnicityMultiComboboxProps) {
export function EthnicityMultiCombobox({ defaultValues, name }: EthnicityMultiComboboxProps) {
const fetcher = useFetcher<SearchCountriesResult>();

useEffect(() => {
fetcher.load('/api/countries/search');
}, []);
}, [fetcher]);

const countries = fetcher.data?.countries || [];

const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
fetcher.submit(
{ search: e.currentTarget.value },
{
action: '/api/countries/search',
method: 'get',
}
);
};

return (
<MultiCombobox defaultValues={defaultValues}>
<MultiComboboxDisplay>
<MultiComboboxValues name={name} />
<MultiComboboxSearch
id={name}
onChange={(e) => {
fetcher.submit(
{ search: e.currentTarget.value },
{
action: '/api/countries/search',
method: 'get',
}
);
}}
/>
<MultiComboboxSearch id={name} onChange={handleSearchChange} />
</MultiComboboxDisplay>

{!!countries.length && (
<ComboboxPopover>
<ul>
{countries.map((country) => {
const label = `${country.flagEmoji} ${country.demonym}`;

return (
<MultiComboboxItem
key={country.code}
label={label}
value={country.code}
>
{label}
</MultiComboboxItem>
);
})}
</ul>
<div className="max-h-48 overflow-y-auto">
{countries.map((country) => (
<MultiComboboxItem key={country.code} label={`${country.flagEmoji} ${country.demonym}`} value={country.code}>
{`${country.flagEmoji} ${country.demonym}`}
</MultiComboboxItem>
))}
</div>
</ComboboxPopover>
)}
</MultiCombobox>
Expand Down
28 changes: 19 additions & 9 deletions packages/core/src/modules/slack/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ type AnswerChatbotQuestionInput = {
* Answers the question asked by the user in its channel w/ the ColorStack bot.
* The uses the underlying `getAnswerFromSlackHistory` function to answer the
* question, and then sends the answer in the thread where the question was
* asked.
* asked. In addition to the newly added reaction functionality
*
* @param input - The question (ie: `text`) to respond to.
*/
export async function answerChatbotQuestion({
*/export async function answerChatbotQuestion({
channelId,
id,
text,
Expand Down Expand Up @@ -85,11 +84,9 @@ export async function answerChatbotQuestion({
});

const questionResult = await isQuestion(text);

if (!questionResult.ok) {
throw new Error(questionResult.error);
}

if (!questionResult.ok || !questionResult.data) {
job('notification.slack.send', {
channel: channelId,
Expand All @@ -99,11 +96,10 @@ export async function answerChatbotQuestion({
threadId: id,
workspace: 'regular',
});

return;
}

job('notification.slack.send', {
const loadingMessage = await job('notification.slack.send', {
channel: channelId,
message: 'Searching our Slack history...',
threadId: id,
Expand All @@ -120,7 +116,6 @@ export async function answerChatbotQuestion({
}

const threads = threadsResult.data;

const answerResult = await getAnswerFromSlackHistory(text, threads);

if (!answerResult.ok) {
Expand All @@ -134,9 +129,24 @@ export async function answerChatbotQuestion({
workspace: 'regular',
});

// TODO: Delete the loading message after the answer is sent.
// Delete the loading message after the answer is sent
await job('slack.message.delete', {
channel: channelId,
messageId: loadingMessage.id,
});

// Added Slack reaction function call!!
await addSlackReaction({
channelId: channelId,
messageId: id, // ID of initial message
reaction: 'colorstack-logo',
userId: userId,
});

//TODO: DELETE LOADING MESSAGE AFTER ANSWER IS SENT
}


type AnswerPublicQuestionInPrivateInput = {
/**
* The ID of the channel where the question was asked (ie: public channel).
Expand Down