Skip to content

Commit

Permalink
add fetch setting api
Browse files Browse the repository at this point in the history
  • Loading branch information
doljko committed Mar 21, 2024
1 parent e8774a1 commit aec2c7a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
38 changes: 29 additions & 9 deletions src/features/Auth/screens/OrganizationSearchScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,35 @@ const isAndroid = Platform.OS === 'android';

const OrganizationSearchScreen = ({ navigation }) => {
const fleetbase = useFleetbase();
const internalInstance = useFleetbase('navigator/v1');
const searchInput = useRef();

const [isLoading, setIsLoading] = useState(false);
const [results, setResults] = useState([]);
const [organizations, setOrganizations] = useState([]);
const [settings, setSettings] = useState();
const [search, setSearch] = useState('');

const fetchOrganizations = async () => {
try {
const adapter = fleetbase.getAdapter();
const response = await adapter.get('organizations');
const response = await adapter.get('organizations', {
with_driver_onboard: true,
});
setOrganizations(response);
console.log('response---->', JSON.stringify(response));
return response;
} catch (error) {
console.error('Error fetching organizations:', error);
return [];
}
};

const fetchSettings = async () => {
try {
const adapter = internalInstance.getAdapter();
const response = await adapter.get('settings/driver-onboard-settings');
setSettings(Object.keys(response.driverOnboardSettings)[0]);
return response;
} catch (error) {
console.error('Error fetching organizations:', error);
Expand All @@ -32,6 +49,7 @@ const OrganizationSearchScreen = ({ navigation }) => {

useEffect(() => {
fetchOrganizations();
fetchSettings();
}, []);

const handleSearch = text => {
Expand All @@ -45,14 +63,16 @@ const OrganizationSearchScreen = ({ navigation }) => {
};

const renderItem = ({ item }) => (
console.log("item", JSON.stringify(item)),
<View style={tailwind('p-4')}>
<TouchableOpacity style={tailwind('p-3 bg-gray-900 border border-gray-800 rounded-xl shadow-sm')} onPress={() => navigation.navigate('SignUp', { organization: item })}>
<View style={tailwind('flex-1 flex-col items-start')}>
<Text style={tailwind('text-gray-100')}>{item.name}</Text>
</View>
</TouchableOpacity>
</View>
console.log('item', JSON.stringify(item)),
(
<View style={tailwind('p-4')}>
<TouchableOpacity style={tailwind('p-3 bg-gray-900 border border-gray-800 rounded-xl shadow-sm')} onPress={() => navigation.navigate('SignUp', { organization: item })}>
<View style={tailwind('flex-1 flex-col items-start')}>
<Text style={tailwind('text-gray-100')}>{item.name}</Text>
</View>
</TouchableOpacity>
</View>
)
);

return (
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use-fleetbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Fleetbase from '@fleetbase/sdk';
import config from 'config';
import { getString, get } from 'utils/Storage';

const useFleetbase = () => {
const useFleetbase = (namespace) => {
let { FLEETBASE_KEY, FLEETBASE_HOST, FLEETBASE_NAMESPACE } = config;
let _DRIVER = get('driver');
let _FLEETBASE_KEY = getString('_FLEETBASE_KEY');
Expand All @@ -22,7 +22,7 @@ const useFleetbase = () => {

const fleetbase = new Fleetbase(FLEETBASE_KEY, {
host: FLEETBASE_HOST,
namespace: FLEETBASE_NAMESPACE,
namespace: FLEETBASE_NAMESPACE ?? namespace,
});

return fleetbase;
Expand Down

0 comments on commit aec2c7a

Please sign in to comment.