Skip to content

Commit

Permalink
Add country select dropdown (#230)
Browse files Browse the repository at this point in the history
Co-authored-by: Anjula Shanaka <[email protected]>
  • Loading branch information
dilankavishka and anjula-sack authored Dec 7, 2024
1 parent 991d87b commit 2d4093f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
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

0 comments on commit 2d4093f

Please sign in to comment.