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

Country select dropdown added #230

Merged
merged 3 commits into from
Dec 7, 2024
Merged
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
22 changes: 22 additions & 0 deletions src/hooks/useCountries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import { API_URL } from '../constants';
import axios from 'axios';

const useCountries = () => {
const { isLoading, error, data } = useQuery({
queryKey: ['countries'],
initialData: [],
queryFn: async () => {
const { data } = await axios.get(`${API_URL}/countries`);
return data.data;
},
});

return {
isLoading,
error,
data,
};
};

export default useCountries;
34 changes: 26 additions & 8 deletions src/pages/MentorRegistration/MentorRegistration.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useLoginModalContext } from '../../contexts/LoginModalContext';
import useMentor from '../../hooks/useMentor';
import { Link } from 'react-router-dom';
import TermsAgreementModalMentor from '../../components/TermsAgreementModal';
import useCountries from '../../hooks/useCountries';

const steps = [
{
Expand Down Expand Up @@ -63,6 +64,12 @@ const MentorRegistrationPage: React.FC = () => {
error: categoriesError,
} = useCategories();

const {
data: allCountries,
isLoading: countriesLoading,
error: countriesError,
} = useCountries();

const {
createMentorApplication,
applicationError,
Expand Down Expand Up @@ -265,14 +272,25 @@ const MentorRegistrationPage: React.FC = () => {
register={register}
error={errors.contactNo}
/>
<FormInput
type="text"
placeholder="United States"
name="country"
label="Country"
register={register}
error={errors.country}
/>
<div className="mb-4">
<label className="block text-sm font-medium text-gray-600">
Country
</label>
{!countriesLoading && (
<select
className="mt-1 p-2 w-1/2 border rounded-md"
{...register('country')}
>
{allCountries.map(
(country: { uuid: string; name: string }) => (
<option key={country.uuid} value={country.uuid}>
{country.name}
</option>
)
)}
</select>
)}
</div>
</>
)}
{currentStep === 1 && (
Expand Down
Loading