Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion app/javascript/src/components/Projects/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getTableData = (project) => {
return project.members.map((member) => {
const hours = member.minutes / 60;
const hour = hours.toFixed(2);
const cost = hours * parseInt(member.hourlyRate);
const cost = (hours * parseInt(member.hourlyRate)).toFixed(2);
return {
col1: (
<div className="text-base text-miru-dark-purple-1000">
Expand Down
7 changes: 4 additions & 3 deletions app/javascript/src/components/Projects/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ToastContainer } from "react-toastify";

import { setAuthHeaders, registerIntercepts } from "apis/axios";
import projectApi from "apis/projects";
import Logger from "js-logger";
import { TOASTER_DURATION } from "constants/index";

import Header from "./Header";
Expand All @@ -15,16 +16,16 @@ export const ProjectList = ({ isAdminUser }) => {

const [showProjectModal, setShowProjectModal] = React.useState<boolean>(false);
const [showDeleteDialog, setShowDeleteDialog] = React.useState<boolean>(false);
const [editProjectData, setEditProjectData] = React.useState<any>(null);
const [editProjectData, setEditProjectData] = React.useState<any>({});
const [deleteProjectData, setDeleteProjectData] = React.useState({});
const [projects, setProjects] = React.useState<IProject[]>([]);

const fetchProjects = async () => {
try {
const res = await projectApi.get();
setProjects(res.data.projects);
} catch (e) {
console.log(e) // eslint-disable-line
} catch (err) {
Logger.error(err);
}
};

Expand Down
72 changes: 38 additions & 34 deletions app/javascript/src/components/Projects/Modals/AddEditProject.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState } from "react";
import projectApi from "apis/projects";
import Logger from "js-logger";
import { X } from "phosphor-react";

const AddEditProject = ({
Expand All @@ -8,44 +9,47 @@ const AddEditProject = ({
setShowProjectModal,
projectData
}) => {
const [client, setClient] = useState<number>(0);
const [projectName, setProjectName] = useState<string>("");
const [projectType, setProjectType] = useState<string>("Billable");
const [clientList, setClientList] = useState<[]>([]);

const [client, setClient] = useState<any>(null);
const [projectName, setProjectName] = useState<any>(null);
const [projectType, setProjectType] = useState<any>("Billable");
const [clientList, setClientList] = useState<any>(null);
const projectId = Number(window.location.pathname.split("/").at(-1)) || editProjectData["id"];

useEffect(() => {
const getClientList = async () => {
projectApi.get()
.then((data) => {
setClientList(data.data.clients);
}).catch(() => {
setClientList({});
});
};
const getProject = async () => {
projectApi.show(projectData.id)
.then((data) => {
setEditProjectData(data.data.project_details);
})
.catch(() => {
setEditProjectData({});
});
};
const getClientList = async () => {
try {
const { data } = await projectApi.get();
setClientList(data.clients);
} catch (error) {
Logger.error(error);
}
};

const getProject = async () => {
try {
const { data } = await projectApi.show(projectId);
setEditProjectData(data.project_details);
} catch (error) {
setEditProjectData({});
}
};

useEffect(() => {
getClientList();
if (projectData) getProject();
}, []);

const handleProjectData = () => {
if (!editProjectData?.name || !clientList.length) return;
const clientName = editProjectData?.client.name || editProjectData?.clientName;
const currentClient = clientList.find(clientItem => clientItem["name"] === clientName);
if (currentClient) setClient(currentClient["id"]);
setProjectName(editProjectData ? editProjectData.name : "");
setProjectType(editProjectData.is_billable || editProjectData.isBillable ? "Billable" : "Non-Billable");
};

useEffect(() => {
if (editProjectData) {
if (clientList) {
const client = clientList.filter(clientItem => clientItem.name == editProjectData.clientName);
setClient(client[0].id);
}
setProjectName(editProjectData ? editProjectData.name : null);
setProjectType(editProjectData.isBillable ? "Billable" : "Non-Billable");
}
handleProjectData();
}, [editProjectData, clientList]);

const handleEdit = () => {
Expand Down Expand Up @@ -106,10 +110,10 @@ const AddEditProject = ({
<select
defaultValue={client}
className="rounded border-0 block w-full px-2 py-1 bg-miru-gray-100 h-8 font-medium text-sm text-miru-dark-purple-1000 focus:outline-none sm:text-base"
onChange={(e) => setClient(e.target.value)}>
onChange={(event) => setClient(+ event.target.value)}>
<option value='0'>Select Client</option>
{clientList &&
clientList.map((e, index) => <option key={index} value={e.id} selected={e.id == client}>{e.name}</option>)}
clientList.map((event, index) => <option key={index} value={event["id"]} selected={event["id"] == client}>{event["name"]}</option>)}
</select>
</div>
</div>
Expand All @@ -122,7 +126,7 @@ const AddEditProject = ({
</label>
</div>
<div className="mt-1">
<input type="text" placeholder=" Enter Project Name" className="rounded appearance-none border-0 block w-full px-3 py-2 bg-miru-gray-100 h-8 font-medium text-sm text-miru-dark-purple-1000 focus:outline-none sm:text-base" value={projectName} onChange={(e) => setProjectName(e.target.value)} />
<input type="text" placeholder=" Enter Project Name" className="rounded appearance-none border-0 block w-full px-3 py-2 bg-miru-gray-100 h-8 font-medium text-sm text-miru-dark-purple-1000 focus:outline-none sm:text-base" value={projectName} onChange={(event) => setProjectName(event.target.value)} />
</div>
</div>
</div>
Expand Down Expand Up @@ -163,7 +167,7 @@ const AddEditProject = ({
};

AddEditProject.defaultProps = {
projectData: null
projectData: {}
};

export default AddEditProject;
15 changes: 10 additions & 5 deletions app/models/wise_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
#
# Table name: wise_accounts
#
# id :integer not null, primary key
# profile_id :string
# recipient_id :string
# id :bigint not null, primary key
# source_currency :string
# target_currency :string
# user_id :integer not null
# company_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# company_id :bigint not null
# profile_id :string
# recipient_id :string
# user_id :bigint not null
#
# Indexes
#
# index_wise_accounts_on_company_id (company_id)
# index_wise_accounts_on_user_id (user_id)
# index_wise_accounts_on_user_id_and_company_id (user_id,company_id) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (company_id => companies.id)
# fk_rails_... (user_id => users.id)
#

class WiseAccount < ApplicationRecord
belongs_to :user
Expand Down