Skip to content

Commit

Permalink
🐛 fix: Supervisor Added And Collaborators, And Manager Service
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrogomes18 committed Oct 27, 2024
1 parent 62151d1 commit 19e6792
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 26 deletions.
43 changes: 28 additions & 15 deletions src/screens/AddCollaborators/SupervisorAdded/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const SupervisorAdded: React.FC = () => {
const { data, setData } = useDataContext();
const [loading, setLoading] = useState(false);
const { user } = useAuth();
const [showPassword, setShowPassword] = useState(false);
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [image, setImage] = useState('');
const [selectedManager, setSelectedManager] = useState<Manager | null>(null);
const [isButtonEnabled, setIsButtonEnabled] = useState<boolean>(false);
const toast = useToast();
const [selectedValue, setSelectedValue] = useState<string>('');
const [isModalVisible, setIsModalVisible] = useState(false);

const options = [
Expand Down Expand Up @@ -70,14 +70,10 @@ const SupervisorAdded: React.FC = () => {
setIsModalVisible(!isModalVisible);
};

const handleSelectChange = (value: string) => {
setSelectedValue(value);
};

const handleCreate = async () => {
try {
setLoading(true);
const managerId = selectedManager?.id || undefined;
const managerId = selectedManager?.id || '';
const companyId = user.companyId;

const supervisor: Supervisor = await SupervisorServices.create({
Expand Down Expand Up @@ -111,14 +107,19 @@ const SupervisorAdded: React.FC = () => {
duration: 3000,
animationType: 'zoom-in',
});
console.log('Erro ao criar supervisor:', error);
} finally {
setLoading(false);
setIsModalVisible(false);
setIsButtonEnabled(false);
}
};

const isCreateDisabled = !name || !selectedValue || !selectedManager;
const toggleShowPassword = () => {
setShowPassword(!showPassword);
};

const isCreateDisabled = !name || !selectedManager;

return (
<KeyboardAvoidingView
Expand Down Expand Up @@ -147,13 +148,25 @@ const SupervisorAdded: React.FC = () => {

<S.DivFileds>
<S.NameField>Senha</S.NameField>
<S.InputField
placeholder="Senha do Supervisor"
value={password}
keyboardType="default"
secureTextEntry={true}
onChangeText={(text) => setPassword(text)}
/>
<S.DivViewTextInput>
<S.InputField
placeholder={'Senha'}
keyboardType="default"
autoCapitalize="none"
secureTextEntry={!showPassword}
value={password}
onChangeText={(text) => setPassword(text)}
/>
<S.BtnIconPass onPress={toggleShowPassword}>
<S.Icon
source={
showPassword
? require('@assets/img/olho_aberto.png')
: require('@assets/img/olho_fechado.png')
}
/>
</S.BtnIconPass>
</S.DivViewTextInput>
</S.DivFileds>
<S.DivFileds>
<S.NameField>Responsável</S.NameField>
Expand All @@ -177,7 +190,7 @@ const SupervisorAdded: React.FC = () => {
source={require('@assets/img/Triangle_Warning.png')}
/>
<S.TextModal>
Tem certeza que deseja adicionar esse vendedor?
Tem certeza que deseja adicionar esse Supervisor?
</S.TextModal>
</S.WrapperConteudo>
<S.BtnYes onPress={handleCreate}>
Expand Down
21 changes: 20 additions & 1 deletion src/screens/AddCollaborators/SupervisorAdded/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { theme } from '@styles/default.theme';

export const Wrapper = styled(View)`
width: 100%;
height: 80%;
height: 630px;
align-items: center;
overflow: hidden;
background-color: ${theme.colors.primary.main};
Expand All @@ -38,10 +38,29 @@ export const NameField = styled(Text)`
letter-spacing: 0.5px;
`;

export const DivViewTextInput = styled(View)`
display: flex;
flex-direction: row;
align-items: center;
`;

export const BtnIconPass = styled(TouchableOpacity)`
width: 16px;
height: 16px;
position: absolute;
right: 10px;
`;

export const Icon = styled(Image)`
width: 16px;
height: 16px;
`;

export const InputField = styled(TextInput)`
::placeholder {
color: #687076;
}
width: 100%;
border-width: 1px;
border-color: #d7dbdf;
background-color: #f1f3f5;
Expand Down
8 changes: 6 additions & 2 deletions src/screens/EvaluateVisit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,12 @@ const EvaluateVisit = () => {
{indexScreen === categories.length && categories.length !== 0 && (
<>
<S.ContainerButton>
<S.ButtonIniciar onPress={overView}>
<S.TextBtn>Ver Resumo do dia de visita</S.TextBtn>
<S.ButtonIniciar onPress={overView} disabled={loading}>
{loading ? (
<ActivityIndicator size="small" color="#fff" />
) : (
<S.TextBtn>Ver Resumo do dia de visita</S.TextBtn>
)}
</S.ButtonIniciar>
<S.Outline onPress={initialNewVisit}>
<S.TextBtnNova>Iniciar nova visita</S.TextBtnNova>
Expand Down
7 changes: 6 additions & 1 deletion src/screens/EvaluateVisit/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ export const ButtonFirst = styled(TouchableOpacity)`
margin-top: 80%;
`;

export const ButtonIniciar = styled(TouchableOpacity)`
export const ButtonIniciar = styled(TouchableOpacity)<{ disabled: boolean }>`
pointer-events: ${({ disabled }) => (disabled ? 'none' : 'auto')};
background-color: ${({ disabled }) => (disabled ? '#B0B0B0' : '#3e63dd')};
opacity: ${({ disabled }) => (disabled ? 0.5 : 1)};
padding: 8px 24px;
background-color: #3e63dd;
width: 90%;
Expand Down
31 changes: 24 additions & 7 deletions src/services/SupervisorServices.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import api from './api';
import ISupervisor from '@interfaces/Supervisor';

interface ICreateSupervisorResponse {
email: string;
image: string;
password: string;
name: string;
companyId: string;
managerId: string;
}
export default class SupervisorServices {
static async create(
newSupervisor: Partial<ISupervisor>
): Promise<ISupervisor> {
const supervisorResponse = await api.post(
'/supervisor/create',
newSupervisor
);
static async create({
email,
companyId,
image,
managerId,
name,
password,
}: ICreateSupervisorResponse): Promise<ISupervisor> {
const supervisorResponse = await api.post('/supervisor/create', {
email,
companyId,
image,
managerId,
name,
password,
});
return supervisorResponse.data;
}
static async getSupervisorById(
Expand Down

0 comments on commit 19e6792

Please sign in to comment.