If a court of competent jurisdiction determines that any contract, proceeding, step or action taken, levy made, or any bonds issued under this part are void, invalid, or unenforceable, or if such court shall for any reason enjoin the issuance or payment of any bonds proposed to be issued or paid under the provisions of this part the court shall also determine whether or not any improvement has been made or services rendered by any person in behalf of and for the benefit of the district under any invalid contract or proceeding or under any contract pursuant to which invalid bonds were issued or proposed to be issued, and if so what part, if any, is of a kind that the district might have lawfully authorized.