add list of available countries
This commit is contained in:
@@ -15,6 +15,12 @@ class Wiass_REST_User_API {
|
|||||||
'callback' => array(__CLASS__, 'validate_token'),
|
'callback' => array(__CLASS__, 'validate_token'),
|
||||||
'permission_callback' => 'is_user_logged_in'
|
'permission_callback' => 'is_user_logged_in'
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'user/get-countries', array(
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => array(__CLASS__, 'get_countries'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -31,4 +37,23 @@ class Wiass_REST_User_API {
|
|||||||
)
|
)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_countries(){
|
||||||
|
$result = [
|
||||||
|
array(
|
||||||
|
'idCountry' => '1',
|
||||||
|
'countryName' => 'Sweden'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'idCountry' => '2',
|
||||||
|
'countryName' => 'Finland'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'idCountry' => '3',
|
||||||
|
'countryName' => 'Denmark'
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
return new WP_REST_Response($result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -124,32 +124,17 @@ const recieveCountries = (json) => ({
|
|||||||
export const fetchCountries = () => {
|
export const fetchCountries = () => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestCountries());
|
dispatch(requestCountries());
|
||||||
|
return client.fetch({
|
||||||
dispatch(recieveCountries([
|
url: `${API_SERVER}/wp-json/wiaas/user/get-countries`,
|
||||||
{
|
method: 'get'
|
||||||
"idCountry": 3,
|
})
|
||||||
"countryName": "Denmark"
|
.then(response => {
|
||||||
},
|
if(response.data){
|
||||||
{
|
dispatch(recieveCountries(response.data));
|
||||||
"idCountry": 4,
|
}
|
||||||
"countryName": "Finland"
|
})
|
||||||
},
|
.catch(error => {
|
||||||
{
|
client.onError(error, dispatch);
|
||||||
"idCountry": 2,
|
});
|
||||||
"countryName": "Sweden"
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
// return client.fetch({
|
|
||||||
// url: `${API_SERVER}/profileSettings/api/getCoutnries`,
|
|
||||||
// method: 'get'
|
|
||||||
// })
|
|
||||||
// .then(response => {
|
|
||||||
// if(response.data){
|
|
||||||
// dispatch(recieveCountries(response.data));
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// client.onError(error, dispatch);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user